Skip to content

fix(openai): normalize strict structured output schemas - #2608

Open
steven-ji wants to merge 2 commits into
agentscope-ai:mainfrom
steven-ji:agent/fix-openai-strict-schema
Open

fix(openai): normalize strict structured output schemas#2608
steven-ji wants to merge 2 commits into
agentscope-ai:mainfrom
steven-ji:agent/fix-openai-strict-schema

Conversation

@steven-ji

Copy link
Copy Markdown
Contributor

Summary

  • normalize strict OpenAI Structured Output schemas before adding them to a request
  • set additionalProperties: false and include every declared property in required for each object schema
  • recursively normalize nested objects, arrays, and $defs without mutating the caller-provided schema
  • add regression coverage for the agent.call(..., Class) schema path and nested schemas

Root cause

ReActAgent enables strict mode for native structured output, while the general JSON Schema generator leaves fields optional by default and does not forbid additional properties. OpenAI rejects that schema when strict: true is used.

Impact

OpenAI calls using typed structured outputs are no longer rejected for missing additionalProperties: false or incomplete/missing required arrays. Other model providers keep their existing schema generation behavior because normalization happens at the OpenAI formatter boundary.

Validation

  • mvn -pl agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-openai -am -Dtest=OpenAIChatFormatterTest -Dsurefire.failIfNoSpecifiedTests=false test
    • 43 tests passed
    • Spotless check passed

Fixes #2548

@CLAassistant

CLAassistant commented Aug 7, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@steven-ji
steven-ji marked this pull request as ready for review August 7, 2026 15:16

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This PR modifies 2 files with 310 lines of diff.

Observations

  • Files changed: 2
  • Test coverage: ✅ Tests included
  • CLA: ✅ Signed

Suggestions

  • Please ensure all public API changes are backward compatible
  • Consider adding unit tests for new logic paths

Automated review by github-manager-bot

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/model Model providers and formatters labels Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core/model Model providers and formatters bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenAI Api Structured Outputs 报错

4 participants