spring-projects / spring-projects/spring-ai

Generated JSON schema fails strict mode checks of Azure

Open
#4,422 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

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 https://github.com/spring-projects/spring-ai/issues/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
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with JsonSchemaGenerator.generateForType and BeanOutputConverter.getJsonSchema, the two schema-generation entry points named in the issue. Compare how each handles nested objects and required fields, then verify the generated schema meets Azure strict-mode requirements: additionalProperties=false and every property included in required.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
ai, api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.