본문으로 건너뛰기
cccskills
무료GitHub에 공개

structured-outputs

Use when needing 100% type-safe, schema-valid data extraction from LLMs. Keywords: structured output, JSON schema, Pydantic, Zod, type-safe, constrained decoding, validation, tool use.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md4.4 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Structured Outputs & Type-Safe Extraction

Overview

The structured-outputs skill provides a framework for ensuring that language models produce data in deterministic, valid, and type-safe formats. This is essential for building robust AI-driven systems where LLM outputs must be consumed by downstream services, databases, or UI components.

When To Use

  • When extracting structured data from unstructured text (e.g., invoices, logs, emails).
  • When controlling tool call arguments to guarantee they meet internal API specifications.
  • When you need to bridge the gap between non-deterministic LLM generation and deterministic software logic.
  • Whenever you see developers relying on regex parsing of unstructured model text.

Core Concepts

  1. Schema Definition: Defining the expected structure using JSON Schema, Pydantic (Python), or Zod (TypeScript).
  2. Validation: Enforcing schema constraints at generation time or post-generation.
  3. Recovery: Handling failures gracefully using self-healing loops.
  4. Constraint Generation: Using techniques to force compliance during the generation process itself.

Patterns

1. Strict Schema Contracts

  • Use Pydantic v2 for Python and Zod for TypeScript to create strongly-typed classes that represent your domain entities.
  • Ensure all fields are explicitly defined with types and, where necessary, constraints (e.g., Field(min_length=1, ...)).

2. Parse-Validate-Retry (Instructor Pattern)

When an LLM fails to match the schema:

  • Catch the validation error.
  • Extract the specific path of the error (e.g., user.address.zipcode).
  • Re-prompt the model by injecting the original prompt, the failed output, and the validation error traceback.
  • Goal: Enable the model to "self-heal" by correcting its own structural mistakes.

3. Token-Level Constrained Decoding (Outlines/CFG)

Instead of relying on retries, constrain the generation at the token level:

  • Use Finite State Machines (FSM) to mask invalid tokens during the generation process.
  • This guarantees 100% schema compliance by definition, effectively eliminating "JSON parsing errors".

4. Schema-Aligned Streaming

  • Implement partial JSON parsing for long-form generations.
  • Use libraries that can identify and stream partial objects (e.g., completing an array element before the next token arrives).

5. BAML Polyglot Contracts

  • Use BAML or similar DSLs to define schemas once.
  • Automatically generate client libraries (Python, TS, Go) to keep the backend and frontend in sync with the LLM schema.

6. Tool Use Schema Design

  • Follow the "KISS" (Keep It Simple, Stupid) principle for tools.
  • Avoid deeply nested schemas unless absolutely necessary.
  • Use meaningful descriptions for every field—the model relies on these descriptions to decide what to populate.

Quality Gates

  • Validation Check: Every LLM output must pass a schema validation function before being treated as trusted data.
  • No Markdown Fences: In production, ensure the pipeline does not depend on looking for ```json blocks. Configure the API to return the raw JSON body if possible, or build robust "json-blobs-only" extractors.
  • Type-Safety: Code using the extracted data should fail to compile (if using TS) or fail during static analysis (if using Python) if it doesn't align with the generated class.

Anti-patterns

  • Un-typed string returns: Using generic text outputs and trying to parse them later.
  • "JSON in markdown fences" dependence: Assuming the model will always use correct markdown tags.
  • Over-nested schemas: Forcing the model to maintain complex hierarchical state, which increases the likelihood of halluncinations.
  • Silent failure: Swallowing JSON parsing errors or schema validation errors instead of logging/retrying/failing the task.
  • Implicit Schemas: Relying on prompt engineering to "describe" the schema instead of providing a formal, machine-readable JSON Schema.

References

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

2d-games

무료

2D game development principles. Sprites, tilemaps, physics, camera.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

VoDaiLocz/kilo-kit-mcp282026년 9월 13일 업데이트

3d-games

무료

3D game development principles. Rendering, shaders, physics, cameras.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

VoDaiLocz/kilo-kit-mcp282026년 9월 13일 업데이트

aesthetic

무료

Create aesthetically beautiful interfaces following proven design principles. Use when building UI/UX, analyzing designs from inspiration sites, generating design images with ai-multimodal, implementing visual hierarchy and color theory, adding micro-interactions, or creating design documentation. Includes workflows for capturing and analyzing inspiration screenshots with chrome-devtools and ai-multimodal, iterative design image generation until aesthetic standards are met, and comprehensive design system guidance covering BEAUTIFUL (aesthetic principles), RIGHT (functionality/accessibility), SATISFYING (micro-interactions), and PEAK (storytelling) stages. Integrates with chrome-devtools, ai-multimodal, media-processing, ui-styling, and web-frameworks skills.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

VoDaiLocz/kilo-kit-mcp282026년 9월 13일 업데이트

Use when implementing or managing persistent, hierarchical memory systems for AI agents. Covers cross-session state, fact supersession, and self-managed memory tools to enable long-term recall and adaptive agent behavior.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

VoDaiLocz/kilo-kit-mcp282026년 9월 13일 업데이트

Use when monitoring, tracing, or debugging agentic workflows in production. Keywords: observability, tracing, OpenTelemetry, Langfuse, latency, token cost, loop detection, telemetry.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

VoDaiLocz/kilo-kit-mcp282026년 9월 13일 업데이트

Use when building self-correcting retrieval systems for AI agents. Keywords: RAG, retrieval, Corrective RAG, Self-RAG, query decomposition, reranking, hallucination, grounding.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

VoDaiLocz/kilo-kit-mcp282026년 9월 13일 업데이트

VoDaiLocz의 스킬 모두 보기

이 스킬의 문제 신고