In addition to the existing json-object
chat response format, OpenAI has introduced the json-schema
format that guarantees the model will always generate responses that adhere to your supplied JSON Schema.
Structured Outputs is the evolution of JSON mode. While both ensure valid JSON is produced, only Structured Outputs ensure schema adherence. Both Structured Outputs and JSON mode are supported in the Chat Completions API
The reference documentation: https://platform.openai.com/docs/guides/structured-outputs
Spring AI provides already, generic, model agnostic, Structured Output Converters utilities, as well as support for the existing OpenAI json_object
response format.
To support the new json_schema
format we need to extend the ResponseFormat type, adding JsonSchema(name, schema, string) type.
Also support for the refusal
field is required.
Comment From: isha382
does Structured output 100% adhere in providing the json as in my case it is not providing complete json always with the required field. Any solution for this?