AgentSkillsCN

json-outputs-implementer

当您需要从文本或图像中提取结构化数据、对内容进行分类,或以保证模式合规的方式格式化 API 响应时,可主动使用此技能。通过与 Pydantic/Zod SDK 的集成,实现 Anthropic 的 JSON 输出模式。内容涵盖模式设计、验证、测试,以及生产优化。此技能不适用于工具参数的验证,也不适用于代理式工作流(此时建议使用 strict-tool-implementer)。

SKILL.md
--- frontmatter
name: json-outputs-implementer
description: >-
  Use PROACTIVELY when extracting structured data from text/images, classifying content, or formatting API responses with guaranteed schema compliance.
  Implements Anthropic's JSON outputs mode with Pydantic/Zod SDK integration.
  Covers schema design, validation, testing, and production optimization.
  Not for tool parameter validation or agentic workflows (use strict-tool-implementer instead).

JSON Outputs Implementer

Overview

This skill implements Anthropic's JSON outputs mode for guaranteed schema compliance. With output_format, Claude's responses are validated against your schema—ideal for data extraction, classification, and API formatting.

What This Skill Provides:

  • Production-ready JSON schema design
  • SDK integration (Pydantic for Python, Zod for TypeScript)
  • Validation and error handling patterns
  • Performance optimization strategies
  • Complete implementation examples

Prerequisites:

  • Decision made via structured-outputs-advisor
  • Model: Claude Sonnet 4.5 or Opus 4.1
  • Beta header: structured-outputs-2025-11-13

When to Use This Skill

Use for:

  • Extracting structured data from text/images
  • Classification tasks with guaranteed categories
  • Generating API-ready responses
  • Formatting reports with fixed structure
  • Database inserts requiring type safety

NOT for:

  • Validating tool inputs → strict-tool-implementer
  • Agentic workflows → strict-tool-implementer

Response Style

  • Schema-first: Design schema before implementation
  • SDK-friendly: Leverage Pydantic/Zod when available
  • Production-ready: Consider performance, caching, errors
  • Example-driven: Provide complete working code
  • Limitation-aware: Respect JSON Schema constraints

Workflow

PhaseDescriptionDetails
1Schema Designworkflow/phase-1-schema-design.md
2SDK Integrationworkflow/phase-2-sdk-integration.md
3Error Handlingworkflow/phase-3-error-handling.md
4Testingworkflow/phase-4-testing.md
5Production Optimizationworkflow/phase-5-production.md

Quick Reference

Python Template

python
from pydantic import BaseModel
from anthropic import Anthropic

class MySchema(BaseModel):
    field: str

response = client.beta.messages.parse(
    model="claude-sonnet-4-5",
    betas=["structured-outputs-2025-11-13"],
    messages=[...],
    output_format=MySchema,
)
result = response.parsed_output  # Validated!

Supported Schema Features

✅ Basic types, enums, format strings, nested objects/arrays, required fields

❌ Recursive schemas, min/max constraints, string length, complex regex

Reference Materials

Related Skills

  • structured-outputs-advisor - Choose the right mode
  • strict-tool-implementer - For tool validation use cases