llm-structured-output

Extract typed JSON, enums, and validated objects from LLM API responses.

Updated Jun 12, 2026
One-click install
npx skills add https://github.com/bilacchi/agents-skills --skill llm-structured-output-bilacchi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: llm-structured-output
Source: https://github.com/bilacchi/agents-skills/tree/main/skills/llm-structured-output
Command: npx skills add https://github.com/bilacchi/agents-skills --skill llm-structured-output-bilacchi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires openai, anthropic, pydantic, zod.

What problem does it solve? LLM responses arrive as free-form text that breaks when fed directly into code, causing malformed JSON, missing fields, and wrong types in production pipelines. This Skill provides schema-constrained extraction patterns across OpenAI, Anthropic, and Google APIs so LLM output can safely feed database writes, API calls, and UI rendering. ## Core Features & Use Cases - Provider-Specific Methods: Covers OpenAI's response_format with JSON Schema and strict mode, Anthropic's tool_use blocks for structured extraction, and Gemini's responseSchema with responseMimeType. - Schema-First Workflow: Guides defining Pydantic models or Zod schemas with field-level descriptions, then validating responses with model_validate() or .parse() before downstream use. - Retry and Validation Logic: Includes patterns for retry loops on validation failures, handling refusals, enum casing mismatches, and empty array edge cases. - Use Case: You are building an invoice processing pipeline where Claude must return vendor names, totals, and line items as typed objects. This Skill shows how to force tool_use output, extract the tool_use block, and validate it before writing to your database. ## Quick Start Ask the AI to extract structured data from text using OpenAI structured outputs or Anthropic tool_use with a Pydantic schema matching your required fields.

Frequently Asked Questions about llm-structured-output

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I get structured JSON output from OpenAI?▼

Use response_format with type json_schema and a full schema definition, setting strict to true to enable constrained decoding. In Python, pass a Pydantic model to client.beta.chat.completions.parse and read the result from message.parsed.

How do I extract structured data from Claude using tool_use?▼

Define a single tool with your target schema as input_schema and set tool_choice to force that tool. Claude returns the structured data in the tool_use content block's input field, so read that block rather than parsing any text blocks.

What is the difference between OpenAI json_object and json_schema modes?▼

json_object mode only guarantees syntactically valid JSON, not schema conformance, so fields and types can be wrong. json_schema mode with strict true uses constrained decoding to guarantee the response matches your exact schema.

Can I use Zod schemas with OpenAI structured outputs?▼

Yes, define a Zod schema in TypeScript and convert it with zodResponseFormat from the openai npm package. Pass the result as response_format to client.beta.chat.completions.parse and read the typed result from message.parsed.

Why does my LLM return empty arrays or wrong enum casing?▼

Empty arrays usually mean the field description is too vague, so make it prescriptive about what to include. Enum casing mismatches happen because strict mode respects exact casing, so lowercase enum values or add a normalization step before validation.

Does structured output guarantee correct values from the LLM?▼

No, constrained decoding only guarantees the response matches the schema's types and structure, not that values are semantically correct. Always validate semantics in application code after schema validation and log raw responses for debugging.