Why do OpenAI completions return inconsistent JSON even with response_format=json? #7386
-
|
I’m calling the completions API with Is there any specific technique to guarantee 100% strict JSON output? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
This results in nearly perfect JSON-only completions. |
Beta Was this translation helpful? Give feedback.
response_format=jsonenforces structure after model generation, not during.For strict JSON:
Set temperature = 0
Use JSON schema hints inside the prompt
Add:
Avoid asking for a mix of code + explanation in the same call
Keep the schema small—large schemas cause drift
This results in nearly perfect JSON-only completions.