/major-ai-skills:structured-outputs-strict-modefrom major-ai-skills
Use provider-supported structured output with a schema, handling refusals, truncation, and validation failures.
Ships in major-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
When asking an LLM for structured JSON output, relying purely on prompt instructions ("Return valid JSON matching this schema") results in schema drift: the model occasionally encloses JSON in markdown code blocks (```json), misses required keys, adds unrequested fields, or outputs invalid data types.
When downstream parsers fail, agents are forced into Error Retry Turns, wasting thousands of tokens and stalling workflows.
Strict Structured Outputs (strict: true) uses Context-Free Grammar (CFG) Constrained Decoding: the API converts the provided JSON Schema into a grammar mask at the transformer sampler layer. Any token that would violate the schema is mathematically masked out during generation - guaranteeing 100% schema adherence with zero markdown wrapper tags.
┌─────────────────────────────────────────────────────────────┐
│ JSON Generation Reliability │
│ │
│ Prompt-Based JSON (Anti-Pattern - 15% Parse Failures): │
│ "Here is the JSON you requested:" │
│ ```json │
│ { "user_id": "101", "role": "admin" } │
│ ``` │
│ ↳ Markdown code fences require regex stripping │
│ ↳ Fails if field `role` drifts into `user_role` │
│ │
│ Strict Structured Outputs (`strict: true` - 100% Exact): │
│ {"user_id":101,"role":"admin"} │
│ ↳ 0 Markdown wrappers, 100% Type-Safe Pydantic Deserialization│
│ ↳ 0 JSON parsing retry turns required │
└─────────────────────────────────────────────────────────────┘
strict: True)Using OpenAI's native Pydantic parser integration:
from pydantic import BaseModel, Field
from openai import OpenAI
from typing import List, Literal
client = OpenAI()
class SecurityVulnerability(BaseModel):
file_path: str = Field(description="Relative path to file")
line_number: int
severity: Literal["LOW", "MEDIUM", "HIGH", "CRITICAL"]
description: str
class AuditReport(BaseModel):
is_safe: bool
vulnerabilities: List[SecurityVulnerability]
def run_strict_security_audit(code_snippet: str) -> AuditReport:
"""Executes security audit with 100% mathematically guaranteed schema adherence."""
completion = client.beta.chat.completions.parse(
model="gpt-4o-2024-08-06",
messages=[
{
"role": "system",
"content": "You are a deterministic security auditor. Audit the provided code."
},
{"role": "user", "content": code_snippet}
],
response_format=AuditReport, # Automatically compiles to strict JSON Schema
temperature=0.0
)
# Returns 100% validated Pydantic model directly
return completion.choices[0].message.parsed
import { OpenAI } from "openai";
import { zodResponseFormat } from "openai/helpers/zod";
import { z } from "zod";
const client = new OpenAI();
const RouteExtractionSchema = z.object({
endpoint: z.string(),
method: z.enum(["GET", "POST", "PUT", "DELETE"]),
authRequired: z.boolean(),
rateLimitRps: z.number(),
});
export async function extractRouteConfig(rawText: string) {
const response = await client.chat.completions.create({
model: "gpt-4o-2024-08-06",
messages: [
{ role: "system", content: "Extract route configurations." },
{ role: "user", content: rawText },
],
response_format: zodResponseFormat(RouteExtractionSchema, "route_extraction"),
});
return JSON.parse(response.choices[0].message.content!);
}
┌───────────────────────────────────────────────────────────────────────────┐
│ 1. ALL FIELDS MUST BE REQUIRED: `strict: true` requires all object keys │
│ to be listed in the `required: [...]` array (use `null` union for opts)│
│ │
│ 2. `additionalProperties: false` MUST BE SET: Prevents hallucinated keys │
│ │
│ 3. USE `Literal` / `z.enum` FOR FINITE VALUES: Constrains string outputs │
└───────────────────────────────────────────────────────────────────────────┘
Running 1,000 automated schema extraction jobs in a production pipeline:
| Approach | Schema Conformance | Markdown Stripping Needed | Retry Turns Required |
|---|---|---|---|
| Standard Prompted JSON | 86.4% | Yes (Regex required) | 136 retry turns ($45.00) |
Strict Mode (strict: true) | 100% (Guaranteed) | No (Pure JSON) | 0 retry turns ($0.00) |
MANDATORY: Whenever structured data extraction or tool argument generation is required, agents must enable
strict: truevia Pydantic or Zod schemas. Never rely on natural language prompt instructions for JSON validation when grammar-constrained decoding is available.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub alivirgo/major-ai-skills --plugin major-ai-skills412 skills in this plugin
/3d-slicerAutomate 3D Slicer research workflows with MRML, VTK/ITK, DICOM data, and Segment Editor. Use for software workflows, not clinical interpretation./abbreviated-git-statusInspect Git branch, staging, and working-tree changes with short or porcelain status output when a compact repository check is needed./ableton-liveAutomate Ableton Live sessions with Python MIDI Remote Scripts, Max for Live, AbletonOSC, and Link synchronization.Other plugins' skills for the same job
/act-as-a-personal-tutorExplain a subject step by step, assess prior knowledge, and use short exercises to check understanding before advancing.