I am using structured mode. I inconsistently get an additional parentheses at the end }
like 40% of the time. Is this a known issue? I am sending the ‘response_format’ of json_schema
. Temperature is set to 0.
Are you using "strict": true
mode, though?
A JSON schema
{
"type": "object",
"properties": {
"key1": {
"type": "string",
},
"key2": {
"type": "string",
}
},
"required": [
"key1",
"key2"
],
"additionalProperties": false
}
Is placed in a strict container
{
"name": "output_json",
"schema": {goes_here},
"strict": true
}
and sent as a response_format:
response_format: {type: "json_schema", "json_schema": {goes_here}}
Putting the strict key in the wrong place will be ignored.
A strict schema should be able to write nothing other than a stop token once the JSON format has been satisfied and closed.
thanks for the reply. I added the strict parameter which helped.
Do I have to add strict to all the nested json fields as well?
Does adding description to every json field helps in getting a better response from the model?
Thanks
No. the strict parameter is the nest level outside of the JSON proper that the AI sees to produce responses. "strict":true
is part of the metadata container when sending to the API, which turns on and builds a conformant logit grammar, where only the mandatory ordered JSON format can be produced. "name"
is placed for the AI as the name of the response format, though, and there may be some benefit in aligning it: calling it “json_schema_for_validated_responses”, “json_response_follows_schema” or to be topical, also guiding the quality of the values filled in.
What is mandatory with this setting is that each object nest level has a “required” with all keys, and each level has "additionalProperties": false
. (both are work the endpoint could have done for you, but doesn’t…)
Description is seen, and as natural language beyond the property name, can help guide the output. When you can’t rely on JSON mechanisms like “maximum”, description can help.