Use structured outputs with a JSON schema so the model always returns data your app can parse, instead of text that crashes JSON.parse.
The AI keeps breaking my app with bad JSON. Make it return clean data
How it works
- Find the parse failures: Vovy looks for errors like "Unexpected token" in your logs and shows examples where the model added prose or code fences around the JSON.
- Define the shape you need: Vovy asks Claude Code to write a JSON schema, a description of each field and its type, from the data your app expects.
- Turn on structured outputs: Claude Code passes the schema using the provider's structured output option, which forces replies to match it instead of just asking nicely.
- Validate on your side: Claude Code adds a validator like Zod so any unexpected reply is caught and retried, not crashing the screen.
- Run a stress test: Vovy sends 30 varied inputs and shows a table: parse success before and after, and any fields the model struggled with.
What you provide
- The AI feature that returns data
- An example of the data you want
What you get
- A JSON schema for your data
- Structured outputs turned on
- Validation and retry logic
- A before and after success rate
FAQ
Isn't telling it "respond in JSON" enough?
Usually, but not always. Structured output modes constrain the model to your schema, which is far more reliable.
Does Claude support this too?
Yes. Claude supports structured outputs and tool use with a schema, and both return data in a fixed shape.
Will it slow things down?
Not noticeably. The first request with a new schema can take a moment longer while it is processed.
Related tasks
All tasks