본문으로 건너뛰기
Skillpedia
프롬프트 및 LLM48k · #5091

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가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/llm-structured-output/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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, or json_schema in OpenAI
  • The user asks about using Anthropic's tool_use or tool_result blocks for data extraction (not for actual tool execution)
  • The user asks about Zod schemas with zodResponseFormat() from the openai npm 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, or grammar-based sampling in 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-expert instead)
  • 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

  1. 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.

  2. 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_schema and set tool_choice: { type: "tool", name: "extract_data" }. Claude returns the structured data in the tool_use content block.
    • Google (Gemini): Use generationConfig.responseSchema with a JSON Schema object and set responseMimeType: "application/json".
    • Local models (llama.cpp, vLLM): Use GBNF grammars or --json-schema flag for constrained decoding at the token level.
  3. Write the schema definition in the user's language. For Python, define a Pydantic BaseModel. For TypeScript, define a Zod schema and convert it with zodResponseFormat(). For raw API calls, write JSON Schema directly.

  4. Include field-level descriptions in the schema. Every field should have a description string 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 bare sentiment: str with no context.

  5. 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."

  6. If using OpenAI's json_schema mode, set "strict": true in the schema definition. This activates constrained decoding where the model can only output tokens that conform to the schema. Without strict: true, the model may still produce invalid JSON.

  7. If using Anthropic's tool_use approach, extract the structured data from response.content by finding the block where type == "tool_use" and reading its input field. Do not parse the text blocks — the structured data lives exclusively in the tool_use block.

  8. 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.

repo: sickn33/agentic-awesome-skills

인기도

GitHub 스타
48k
순위
#5091
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬