Asked about A prompt is a specification
A prompt works most of the time but occasionally returns the wrong format. What do you do?
An answer that works
First check whether the task and output format are fully specified, including what to do in the empty or unknown case. Then lower the temperature, since format drift is sampling variation. Then use schema-constrained output, which makes the shape a guarantee rather than a request.
Then they push further
You added a schema and it still fails on 1% of requests. Now what?
Look at the failing inputs. Check for truncation from max_tokens, for unusual inputs such as very long or empty ones, and for inputs that contain their own formatting. Then decide between fixing the prompt, validating and retrying once, or failing cleanly.
Is retrying on failure a good idea?
Once, with the validation error passed back, is usually cheap and fine. Unlimited retries hide a real problem and multiply cost. Count retries so you notice when they climb.
What gets marked up
Marked up for reaching for structured output and validation rather than more wording, and for reading the failing inputs before changing anything.
Reading an answer is not being able to give one. The section that teaches this is A prompt is a specification, 3 hours of Prompting.
Learn this properlyAlso asked about Prompting