-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
After upgrading Spring AI from 1.0.1
to 1.0.2
, my chat client began throwing this exception:
400 Bad Request: {
"error": {
"message": "Invalid schema for response_format 'custom_schema': In context=('properties', [MASKED]), 'additionalProperties' must be supplied and set to false.",
"type": "invalid_request_error",
"param": "response_format",
"code": null
}
}
The problem seems to arise because the strict
property is now mapped correctly (probably changed via #3928), which exposes previously “invalid” JSON schemas.
I’m looking for the correct way to generate a JSON schema that satisfies strict mode—that is, where additionalProperties
is set to false
in every nested object and every field is listed in required
.
So far I’ve configured the response format like this:
AzureOpenAiResponseFormat.builder()
.type(AzureOpenAiResponseFormat.Type.JSON_SCHEMA)
.jsonSchema(JsonSchemaGenerator.generateForType(JSON_SCHEMA_CLASS))
.build();
However, JsonSchemaGenerator.generateForType(JSON_SCHEMA_CLASS)
sets additionalProperties=false
only on the top-level object, not on nested ones.
I also tried BeanOutputConverter.getJsonSchema
. That method correctly sets additionalProperties=false
on nested objects, but it doesn’t mark every field as required, leading to a different exception:
400 Bad Request: {
"error": {
"message": "Invalid schema for response_format 'custom_schema': In context=('properties', [MASKED]), 'required' must be supplied and must include every key in properties. Missing '[MASKED]'.",
"type": "invalid_request_error",
"param": "response_format",
"code": null
}
}