Skip to content

fix(prompt): keep requiredProperties of nested objects in OpenAI-compatible tool schema - #2256

Open
Aditya Nikam (adityaanikam) wants to merge 1 commit into
JetBrains:developfrom
adityaanikam:fix-openai-nested-required-properties
Open

Aditya Nikam (adityaanikam) wants to merge 1 commit into
JetBrains:developfrom
adityaanikam:fix-openai-nested-required-properties

Conversation

@adityaanikam

Copy link
Copy Markdown

OpenAICompatibleToolDescriptorSchemaGenerator wrote only the top-level required list. The ToolParameterType.Object branch of fillJsonSchema never wrote requiredProperties, so every property of a nested object, for example the items of a list of objects, became optional in the schema sent to the model. OllamaToolDescriptorSchemaGenerator already writes it.

The Object branch now writes required after properties when requiredProperties is not empty, so objects without required properties produce the same schema as before.

Tests: added testNestedObjectInListKeepsRequiredProperties, which reproduces the issue, and updated the expected JSON of object_with_properties_and_additionalProperties, which had a note saying the converter does not emit required inside a nested object. Both fail on the unmodified generator and pass with the change.

Verification: ran jvmTest for prompt-executor-openai-client-base, and for the clients that inherit this generator (openai, openrouter, deepseek, mistralai, dashscope). All pass. I could not run the full build locally because the module also has an Android target and I have no Android SDK, so I am relying on CI for that.

closes #2255

…atible tool schema

OpenAICompatibleToolDescriptorSchemaGenerator wrote only the top-level
required list. The ToolParameterType.Object branch never wrote
requiredProperties, so every property of a nested object became optional
in the schema sent to the model. Write required after properties when
requiredProperties is not empty, so objects without required properties
produce the same schema as before.

closes JetBrains#2255
Copilot AI lite review requested due to automatic review settings September 26, 2026 19:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified that would block approval.

Review effort: Lite
Findings: None

What changed in this PR

Fixes OpenAI-compatible tool schemas so nested object properties retain their required fields.

Changes:

  • Emit nested required arrays for object parameter types.
  • Add regression coverage for nested objects in lists and update expected output.
File Description
prompt/​prompt-executor/​prompt-executor-clients/​prompt-executor-openai-client-base/​src/​commonTest/​kotlin/​ai/​koog/​prompt/​executor/​clients/​openai/​base/​OpenAICompatibleToolDescriptorConverterTest.kt Updated as part of this pull request.
prompt/​prompt-executor/​prompt-executor-clients/​prompt-executor-openai-client-base/​src/​commonMain/​kotlin/​ai/​koog/​prompt/​executor/​clients/​openai/​base/​OpenAICompatibleToolDescriptorSchemaGenerator.kt Updated as part of this pull request.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAICompatibleToolDescriptorSchemaGenerator drops requiredProperties of nested object parameters

2 participants