llm-structured-output
하는 일
이 스킬은 AI가 자유로운 글 대신 텍스트에서 특정하고 체계적인 정보(JSON 형식의 데이터 등)를 추출하도록 돕습니다. 추출된 정보가 정해진 형식을 따르고 프로그램의 다른 부분에서 안정적으로 쓰이도록 합니다.
사용하는 경우
- ✓목록이나 연락처 정보처럼 정확한 형식으로 데이터를 받아야 할 때.
- ✓AI 출력을 다른 소프트웨어가 바로 사용해야 하는 시스템을 만들 때(예: 데이터베이스 저장).
- ✓AI가 엉망이거나 잘못된 형식의 데이터를 반환해 믿을 만한 해결책이 필요할 때.
스킬 링크
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/llm-structured-output/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“‘안녕하세요, 제 이름은 Maria Silva이고 연락처는 maria.silva@email.com, 전화번호는 11 98765-4321입니다.’ 이 메시지에서 이름, 이메일, 전화번호를 뽑아 JSON 형식으로 반환해 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
AI는 ‘스키마’(데이터가 어떻게 구성되어야 하는지 정한 템플릿)를 따르도록 지시받습니다. 또한 OpenAI, Anthropic, Google 같은 각 AI 제공자의 전용 도구를 사용해 출력이 스키마와 정확히 일치하도록 합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
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)
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.
- OpenAI (gpt-4o, gpt-4o-mini): Use
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.
…
자주 묻는 질문
AI가 때때로 잘못된 JSON을 반환하는 이유는 무엇인가요?
AI에게 형식이 올바르게 지시되지 않았거나, AI 제공자가 출력을 스키마에 맞게 강제하는 충분한 장치가 없을 때 생길 수 있습니다. 이 스킬은 그런 장치를 사용하는 방법을 알려 줍니다.
‘스키마’란 무엇인가요?
예상되는 데이터의 구조를 정의하는 틀이나 설계도와 같습니다. 어떤 필드가 있어야 하는지, 각 필드가 어떤 종류의 정보(텍스트, 숫자 등)를 담는지, 필수인지 선택인지를 정합니다.
이것은 모든 AI에서 작동하나요?
이 스킬은 OpenAI, Anthropic, Google 같은 주요 제공자의 API를 사용하는 방법에 초점을 둡니다. 로컬에서 실행되는 모델에도 비슷한 기법이 있습니다.
상세 정보
작성자의 원본 설명
Get reliable JSON, enums, and typed objects from LLMs using response_format, tool_use, and schema-constrained decoding across OpenAI, Anthropic, and Google APIs.
인기도
- GitHub 스타
- 48k
- 순위
- #5091
- 라이선스
- MIT
- 업데이트
- 2026. 10. 15.
댓글
- …
이 저장소의 다른 스킬
00-andruia-consultant
48k에이전트가 AI 프로젝트를 시작하거나 개선할 수 있도록 코드를 분석하고 스페인어로 실행 계획을 세워 줍니다.
007
48k에이전트가 보안 감사와 위협 모델링을 수행해 공격과 취약점으로부터 프로젝트를 보호하도록 돕습니다.
10-andruia-skill-smith
48k에이전트가 AI 도구의 작동 방식을 정의하고 문서를 쓰며 구조를 검증하도록 돕습니다.
20-andruia-niche-intelligence
48k에이전트가 신뢰할 수 있는 자료를 바탕으로 특정 산업의 맥락, 규칙, 사용 패턴, 위험을 정리한 요약을 만들도록 돕습니다.
비슷한 스킬
writing-skills
311k에이전트를 위한 새 스킬을 작성하고, 각 스킬이 실제로 에이전트의 행동을 바꾸는지 사용하기 전에 테스트하도록 가르칩니다.
writing-for-agents
310k스킬, AGENTS.md, CLAUDE.md 등 AI 에이전트가 읽는 문서를 명확하게 쓰는 방법을 알려 주어 에이전트가 예측 가능하게 행동하도록 돕습니다.
bengali-nlp
280k에이전트가 벵골어 텍스트를 처리하도록 돕습니다. 언어를 이해하고 다루며, 텍스트를 정규화하고 고유한 특징을 처리합니다.