Skip to content

[integration][ollama] Tolerate tool schemas without a 'required' key - #1026

Open
Zhuoxi2000 wants to merge 1 commit into
apache:mainfrom
Zhuoxi2000:fix-ollama-required-npe
Open

[integration][ollama] Tolerate tool schemas without a 'required' key#1026
Zhuoxi2000 wants to merge 1 commit into
apache:mainfrom
Zhuoxi2000:fix-ollama-required-npe

Conversation

@Zhuoxi2000

Copy link
Copy Markdown
Contributor

Linked issue: #1014

Purpose of change

OllamaChatModelConnection.convertToOllamaTools assumed the tool schema always carries a required list, but required is optional in JSON Schema and SchemaUtils.generateSchema only emits it when at least one parameter is required. A Java @Tool whose parameters are all optional therefore produced a valid schema that crashed the Ollama connector with an NPE before the request reached the server. The same shape can come from external tools (e.g. an MCP tool with only optional parameters), so this hardens the consumer rather than changing SchemaUtils: a missing required list is treated as empty, and all-optional tools convert normally with every property marked required(false).

Tests

New OllamaChatModelConnectionTest (the module previously had no connection test): a schema without a required key converts with every property optional, and a schema with a required key still marks the listed parameters required. Both are pure unit tests of the conversion — no Ollama server needed. convertToOllamaTools was narrowed from private to package-private for test access.

API

None.

Documentation

  • doc-needed
  • doc-not-needed
  • doc-included

Was this patch authored or co-authored using generative AI tooling?

  • Yes
  • No

If yes, include a Generated-by: <tool name and version> (<model name and version>) line, for example Generated-by: Claude Code 2.1.226 (Claude Opus 4.6), in the commit message so it reaches Git history. Repeat the same line here for reviewer visibility. See the ASF generative tooling guidance.

Generated-by: Claude Fable 5

@github-actions github-actions Bot added doc-not-needed Your PR changes do not impact docs fixVersion/0.4.0 priority/major Default priority of the PR or issue. labels Aug 18, 2026
@Zhuoxi2000
Zhuoxi2000 marked this pull request as ready for review August 18, 2026 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs fixVersion/0.4.0 priority/major Default priority of the PR or issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant