structured-output-contract
Use whenever an LLM's output is consumed by code (parsed, stored, or dispatched) — define a JSON Schema and enforce it with constrained decoding or strict tool-use, instead of prompt-and-hope plus reg
Files1
View on GitHubSKILL.mdproject-trajectory/skills/structured-output-contract/SKILL.md
GitHubWhen to use. Any machine-consumed model output. Why: free-text parsing breaks in production; constrained decoding to a schema is ~100% valid vs 95–99% for plain function-calling.
Procedure.
- Write the JSON Schema / Pydantic model. Set
additionalProperties: false; make optional fields nullable-and-required. - Enforce it: native strict structured output (Anthropic/OpenAI) or constrained decoding (Outlines/XGrammar) for open models — not post-hoc regex.
- Add a validate-then-retry layer for the residual failures.
- Done when: a malformed-output test can't get past the boundary (schema rejects it), demonstrated with a pasted failing-then-passing run.
Knowledge: KNOWLEDGE-LIBRARY.md §A3. Example: the Outlines snippet there.