structured-output

Installation
SKILL.md

Structured Output

Prompted JSON — "reply as JSON" in the system prompt — fails on ~2-8% of calls in the wild: stray prose before the object, trailing commas, unescaped quotes, code fences. That failure rate is fine for a demo and fatal for a loop that runs a thousand times.

The hierarchy — use the strongest that fits

  1. Tool use with schema (best) — declare a tool with a JSON Schema for its input. Force the model to call that tool. The API validates the arguments against the schema before you see them. Malformed JSON never leaves the model. Use this whenever the downstream is a real parser.

  2. JSON mode / response_format (good) — where supported. Guarantees a valid JSON object at the top level; does not guarantee schema conformance. Cheap upgrade over prompted-JSON.

  3. Prompted JSON with strict rules (fallback) — for models/tiers without tool use. Say "output ONLY the JSON object, no code fences, no prose", give an example, and validate on receive. Assume ~5% failure and handle it.

The validate-and-retry pattern

call → parse → if fail: retry once with the parse error appended → parse → if fail: hard fail
Installs
18
GitHub Stars
757
First Seen
Jul 8, 2026
structured-output — archive228/loopkit