When to use this skill
- When LLM output must strictly follow a JSON/object schema
- When it must be reliably handed off to subsequent automation (storage/analysis/API calls)
- When verifiable structured output matters more than free-form prose
Instructions
Step 1) Schema-first design
- First define the Pydantic model and separate required/optional fields
- Specify enum/range/regex constraints
- Design error messages in a form the user can correct
Step 2) Agent + Tool combination
- Unify tool inputs and outputs with Pydantic types
- Separate retry rules for failures (missing fields/type mismatch)
- If the model output does not comply with the schema, immediately re-ask (repair prompt)
Step 3) Validation/recovery loop
- Categorize ValidationError (missing/format/logic)
- If the same error repeats, reconsider schema complexity rather than the prompt
- Include confidence flags (validated, repaired, failed) in the final result
Step 4) Operational application
- Perform secondary validation (server-side) before DB storage
- Versioned schema (
v1,v2) to manage compatibility - Observation metrics: first-pass success, retry rate, field error rate
Examples
- Request: "I want to always receive research results as JSON in the same format and put them into the pipeline"
- Application:
ResearchSummaryAfter defining the schema, forcibly validate the Agent result - Result: reduced parsing failure rate, stabilized subsequent automation
Best practices
- Translate natural language requirements into a schema first.
- Start with a small schema and expand it gradually.
- Improve the quality of error classification before the number of retries.