Structured Output That Parses Every Time

Structured Output That Parses Every Time

Getting strict JSON out of an API, and what to do about the one response in fifty that is not.

mistral api json structured parsing

What it is for

Structured output is not a formatting preference, it is a parsing contract, and the response that breaks it always arrives eventually. This covers getting strict JSON reliably and what to do about the one response in fifty that still is not valid.

The skill

For any programmatic call, constrain the output and then still defend against
it being wrong.

In the request:
- Give the exact schema in the system message, as a literal example object with
  real-looking values, not a prose description of the fields.
- Say "Return only the JSON object. No markdown fence, no prose, no trailing
  commentary." Models add a fence unless told not to.
- Set temperature to 0. Sampling variance in a structured field is a parse
  error, not creativity.
- Use the API's JSON mode if available. It is a stronger constraint than any
  wording.

In the client, regardless:
- Strip a leading and trailing markdown fence before parsing. It costs three
  lines and removes the commonest failure entirely.
- On a parse failure, retry ONCE with the raw text and the parser error
  appended. A second failure is a real problem; a first is usually a fence.
- Validate the parsed object against the schema before use. "It parsed" and
  "it has the fields I need" are different claims.

How to install it

1. Open the tool and start a new conversation, project or template.
2. Paste the text below wherever the tool keeps standing instructions
   — usually called system prompt, instructions, or persona.
3. Save it so it applies to every run rather than a single message.

Did it work for you?

Where it came from

Skills app Original