sickn33/antigravity-awesome-skills/llm-structured-output
Claude Code and agent skill by sickn33/antigravity-awesome-skills
- community
Checking that the SKILL.md file is still in the repository.
Get reliable JSON, enums, and typed objects from LLMs using response_format, tool_use, and schema-constrained decoding across OpenAI, Anthropic, and Google APIs.
Install
npx vskill@latest install sickn33/antigravity-awesome-skills/llm-structured-outputSKILL.md
LLM Structured Output
What This Skill Does
Extract typed, validated data from LLM API responses instead of parsing free-text. This skill covers the three main approaches: OpenAI's response_format with JSON Schema, Anthropic's tool_use block for structured extraction, and Google's responseSchema in Gemini. You will learn when each approach works, when it breaks, and how to build retry logic around schema validation failures that every production system encounters.
When to Use This Skill
- The user needs to extract structured data (JSON objects, arrays, enums) from an LLM response
- The user is building a pipeline where LLM output feeds directly into code (database writes, API calls, UI rendering)
- The user asks about
response_format,json_mode,json_object, orjson_schemain OpenAI - The user asks about using Anthropic's
tool_useortool_resultblocks for data extraction (not for actual tool execution) - The user asks about Zod schemas with
zodResponseFormat()from theopenainpm package - The user needs to parse LLM output into Pydantic models using
instructor,marvin, or manual validation - The user is getting malformed JSON, missing fields, or wrong types from LLM responses and needs a fix
- The user asks about
controlled generation,constrained decoding, orgrammar-based samplingin local models
Do NOT use this skill when:
- The user wants free-form text generation (summaries, essays, chat)
- The user is asking about Zod for form validation or API input validation (use
zod-validation-expertinstead) - The user needs prompt engineering for better text quality (not structure)
- The user wants to call real external tools/APIs (this skill covers using tool_use as a structured output hack, not actual tool orchestration)
Examples use historical model IDs and SDK helper paths; verify availability and pin a supported SDK/model before deployment. Strict output support and schema subsets differ by provider/API. A schema-valid value is untrusted data, never authorization for a database write or external call. Keep source-document instructions separate from the extraction instruction, and enforce allowed actions in application code.
Core Workflow
- Identify the target schema. Ask the user what fields they need extracted. Define every field with its type, whether it's required or optional, and valid enum values if applicable. Do not proceed without a concrete schema.
- Choose the provider-appropriate method:
- OpenAI (gpt-4o, gpt-4o-mini): Use
response_format: { type: "json_schema", json_schema: { ... } }. This enables Structured Outputs with guaranteed schema conformance via constrained decoding. - Anthropic (Claude): Define a single tool with the target schema as
input_schemaand settool_choice: { type: "tool", name: "extract_data" }. Claude returns the structured data in thetool_usecontent block. - Google (Gemini): Use
generationConfig.responseSchemawith a JSON Schema object and setresponseMimeType: "application/json". - Local models (llama.cpp, vLLM): Use GBNF grammars or
--json-schemaflag for constrained decoding at the token level.
- Write the schema definition in the user's language. For Python, define a Pydantic
BaseModel. For TypeScript, define a Zod schema and convert it withzodResponseFormat(). For raw API calls, write JSON Schema directly.
- Include field-level descriptions in the schema. Every field should have a
descriptionstring that tells the model what to put there. Models use these descriptions as implicit prompt instructions — a field described as"The user's sentiment as positive, negative, or neutral"produces better results than a baresentiment: strwith no context.
- Set the system prompt to reinforce structure. Tell the model its job is data extraction, not conversation. Example:
"You are a data extraction system. Analyze the input and return the requested fields. Do not include explanations outside the JSON structure."
- If using OpenAI's
json_schemamode, set"strict": truein the schema definition. This activates constrained decoding where the model can only output tokens that conform to the schema. Withoutstrict: true, the model may still produce invalid JSON.
- If using Anthropic's tool_use approach, extract the structured data from
response.contentby finding the block wheretype == "tool_use"and reading itsinputfield. Do not parse the text blocks — the structured data lives exclusively in the tool_use block.
- Validate the response against the schema in your application code. Even with constrained decoding, validate with Pydantic's
model_validate()or Zod's.parse()before passing data downstream. This catches semantic issues (empty strings, out-of-range numbers) that schema conformance alone cannot prevent.
- Build a retry loop for validation failures. When validation fails, send the original input plus the failed output and the validation error back to the model with an instruction like
"Your previous output failed validation: {error}. Fix the output."Cap retries at 3 attempts.
- Log schema/model versions, request IDs, validation outcomes and redacted diagnostic samples. Keep raw inputs/responses only when authorized and necessary, with access controls and retention limits; never routinely log secrets or sensitive source documents. When structured output breaks in production, you need these logs to determine whether the failure was a schema design issue, a prompt issue, or a model regression.
Examples
Example 1: OpenAI Structured Outputs with Pydantic (Python)
Example 2: Anthropic tool_use for Structured Extraction (Python)
Example 3: TypeScript with Zod + zodResponseFormat
Never Do This
- Never use `response_format: { type: "json_object" }` without a schema. This is OpenAI's legacy JSON mode — it guarantees valid JSON syntax but not schema conformance. The model can return
{"result": "hello"}when you expected{"name": str, "age": int}. Always usejson_schemawith a full schema definition instead.
- Never parse Anthropic's text blocks for structured data. When using
tool_choiceto force structured output, the data is in thetool_usecontent block, not in anytextblock. Parsingresponse.content[0].textwill either return empty string or a conversational preamble — never the data you need.
- Never define schema fields without descriptions. A field named
statuswith no description can mean HTTP status, order status, or review status. Models use field descriptions as extraction instructions. Omitting them is equivalent to omitting half your prompt.
- Never use `additionalProperties: true` in strict mode schemas. OpenAI's strict mode requires
additionalProperties: falseon every object in the schema. If you set it to true or omit it, the API rejects the request with a 400 error, not at response time — you will never get a response at all.
- Never put extraction instructions only in the user message and not the system prompt. The system prompt has higher attention weight for behavioral instructions. Putting "extract the following fields" only in the user message alongside the source text forces the model to split attention between the instruction and the data. System prompt defines behavior; user message provides input data.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 98 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/llm-structured-output/SKILL.md
Popularity
- Repository stars
- 35,853
- Repository forks
- 5,881
- Repository npm downloads, 7 days
- 7,435
- 7-day trend score
- 74
Stars and forks are for the whole GitHub repository, not this skill alone. Downloads are for the repository's npm package. Refreshed 30 Apr 2026, 6 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/sickn33/antigravity-awesome-skills/llm-structured-output)