llm-structured-output
Fungsinya
Skill ini membantu AI mengekstrak informasi tertentu yang terstruktur (misalnya data dalam format JSON) dari sebuah teks, alih-alih hanya menghasilkan teks bebas. Skill ini memastikan informasi yang diekstrak mengikuti format yang telah ditentukan dan dapat diandalkan untuk digunakan di bagian lain dari sebuah program.
Kapan dipakai
- ✓Ketika Anda membutuhkan AI mengembalikan data dalam format yang tepat, seperti daftar item atau detail kontak.
- ✓Ketika membangun sistem yang output AI-nya harus langsung dipakai oleh software lain (misalnya disimpan ke database).
- ✓Jika AI mengembalikan data yang berantakan atau formatnya salah dan Anda membutuhkan solusi yang andal.
Link skill
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/llm-structured-output/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
“Ekstrak nama, email, dan nomor telepon dari pesan ini dan kembalikan dalam format JSON: 'Halo, nama saya Maria Silva dan kontak saya maria.silva@email.com, telepon 11 98765-4321.'”
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
AI diinstruksikan untuk mengikuti 'schema' (cetakan tentang bagaimana data harus disusun) dan menggunakan fitur khusus dari setiap penyedia AI (OpenAI, Anthropic, Google) agar output sesuai dengan schema secara tepat.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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.
…
Pertanyaan umum
Mengapa AI kadang mengembalikan JSON yang tidak valid?
Hal ini bisa terjadi jika AI tidak diberi instruksi format yang benar, atau jika penyedia AI tidak memiliki mekanisme yang kuat untuk memaksa output mengikuti schema. Skill ini mengajarkan cara menggunakan mekanisme tersebut.
Apa itu 'schema'?
Schema seperti cetakan atau cetak biru yang mendefinisikan struktur data yang diharapkan: field apa saja yang harus ada, jenis informasi setiap field (teks, angka, dan sebagainya), serta apakah field tersebut wajib atau opsional.
Apakah ini berlaku untuk semua AI?
Skill ini berfokus pada cara melakukannya dengan API dari penyedia besar seperti OpenAI, Anthropic, dan Google. Untuk model yang dijalankan secara lokal, teknik serupa juga tersedia.
Detail
Deskripsi asli dari pembuat
Get reliable JSON, enums, and typed objects from LLMs using response_format, tool_use, and schema-constrained decoding across OpenAI, Anthropic, and Google APIs.
Popularitas
- Bintang GitHub
- 48k
- Peringkat
- #5091
- Lisensi
- MIT
- Diperbarui
- 15/10/2026
Komentar
- …
Skill lain dari repositori ini
00-andruia-consultant
48kMembantu agent Anda memulai atau meningkatkan proyek AI. Agent menganalisis kode, menyarankan tools, dan membuat rencana aksi dalam bahasa Spanyol.
007
48kMemungkinkan agent Anda melakukan audit keamanan dan threat modeling. Berguna untuk melindungi proyek dari serangan dan celah keamanan.
10-andruia-skill-smith
48kMembantu agent Anda membuat atau meningkatkan tools AI. Agent mendefinisikan cara kerja tools, menulis dokumentasi, dan memvalidasi strukturnya.
20-andruia-niche-intelligence
48kMemungkinkan agent Anda membuat ringkasan industri tertentu. Berguna untuk memahami konteks, aturan, pola penggunaan, dan risiko proyek dengan sumber terpercaya.
Skill serupa
writing-skills
311kMengajari agent Anda menulis skill baru dan menguji setiap skill lebih dulu, memastikan skill itu benar-benar mengubah perilaku agent.
writing-for-agents
310kMenjelaskan cara menulis instruksi yang jelas untuk agent AI, termasuk file skill, AGENTS.md, dan CLAUDE.md, agar perilaku agent dapat diprediksi.
bengali-nlp
280kMembuat agent Anda memproses teks Bahasa Bengali. Membantu memahami dan mengolah bahasa tersebut, termasuk normalisasi teks dan karakteristik uniknya.