Define a schema
List every key, type, allowed value, and whether it is required. Specify how missing or uncertain information must be represented.
Remove competing prose
Ask for one JSON value with no markdown fence or commentary. When supported, prefer the provider’s structured-output or schema feature over prompt-only formatting.
Validate outside the model
Parse the response, validate it against a schema, reject unexpected fields when appropriate, and retry with the validation error. Never treat generated JSON as trusted code or SQL.
Test edge cases
Include empty inputs, quotes, Unicode, long strings, ambiguous categories, and unavailable facts. Correct escaping and stable null behavior matter as much as the happy path.
Worked example
Extract an appointment from [MESSAGE].
Required keys: date, time, timezone, missing_fields.
Use null for facts not supplied. Never guess a timezone.
Example shape (illustrative, not a model result):
{"date":"2026-10-15","time":null,"timezone":null,"missing_fields":["time","timezone"]}How to check the result
Parse the response before consuming it. Check valid date ranges separately from JSON syntax. Reject extra fields if your contract requires that, and ensure null has a defined meaning in downstream code.