Skip to content

[spring-ai] ToolConverter silently drops enum and items from tool parameter schemas #1609

Description

@caps-xia

Describe the Bug

ToolConverter#convertSchemaToSpringAi (used by convertToSpringAiTools) maps only
type, properties, description and required when converting a genai Schema
to a Spring AI ToolDefinition input schema. enum and items are silently
dropped.

Impact: any ADK tool whose parameters use enum-constrained strings or typed arrays —
including the mainstream path of annotated FunctionTool methods (enum Java fields,
List<String> parameters) — ends up with a degraded schema sent to the model:
enum parameters become free-form strings (models then send invalid values), and array
parameters lose their element type.

Steps to Reproduce

  1. Define a BaseTool whose declaration() returns a FunctionDeclaration with
    parameters containing an enum property and an array-with-items property.
  2. Convert it via new ToolConverter().convertToSpringAiTools(...).
  3. Inspect getToolDefinition().inputSchema() — no enum, no items.

Expected Behavior

enum, items (and ideally format, nullable, minItems/maxItems) survive the
conversion, so the model receives the same parameter constraints the ADK tool declared.

Observed Behavior

Identical output on 1.9.0 and 1.11.0 (latest):

declared: color = string + enum ["red","green"],  tags = array of string (items)
converted inputSchema:
{"description":"参数","type":"object","properties":{"color":{"description":"颜色","type":"string"},"tags":{"description":"标签","type":"array"}},"required":["color"]}
                                   ^ no "enum"                      ^ no "items"

Environment Details

  • ADK Library Version: verified on 1.9.0 and 1.11.0 with identical output;
    on current main, convertSchemaToSpringAi still only emits type/properties
  • OS: macOS (logic bug, OS-independent)
  • TS Version: N/A (Java)

Model Information

Model-independent — the loss happens in tool-definition conversion before any model
call. Observed with GLM via an OpenAI-compatible gateway.

Regression

N/A.

Additional Context

We maintain a patched bridge for this reason (among others): we bypass the wrapped
conversion and restore the original callbacks per tool name so the raw schema reaches
the model. A minimal fix is to map enum_ and items in convertSchemaToSpringAi;
serializing the genai Schema to JSON directly would also work and would future-proof
against further field drift.

Minimal Reproduction Code

Schema color = Schema.builder().type("string")
        .description("颜色").enum_(List.of("red", "green")).build();
Schema tags = Schema.builder().type("array")
        .description("标签").items(Schema.builder().type("string").build()).build();
Schema params = Schema.builder().type("object")
        .properties(Map.of("color", color, "tags", tags))
        .required(List.of("color"))
        .build();

BaseTool tool = new BaseTool("probeTool", "probe") {
    @Override public Optional<FunctionDeclaration> declaration() {
        return Optional.of(FunctionDeclaration.builder()
                .name("probeTool").description("probe").parameters(params).build());
    }
    @Override public Single<Map<String, Object>> runAsync(Map<String, Object> args, ToolContext ctx) {
        return Single.just(Map.of());
    }
};

String schema = new ToolConverter()
        .convertToSpringAiTools(Map.of("probeTool", tool))
        .get(0).getToolDefinition().inputSchema();
// schema contains no "enum" and no "items"

How often has this issue occurred?

Always (100%) — every enum/array tool parameter.

Activity

  1. self-assigned this
    on Oct 5, 2026
  2. added theissue type on Oct 5, 2026
  3. caps-xia commented on Oct 5, 2026

    @caps-xia
    ContributorAuthor

    Thanks for triaging, @hirematha!

    I also hit this in production — my current workaround restores the original tool callbacks so the unconverted schema reaches the model, so I have good reproduction coverage for the failure mode as well.

    Happy to submit a PR unless one is already in progress. On the shape of the fix in convertSchemaToSpringAi, I see two options:

    1. Minimal fix — additionally map enum and items, recursing into nested schemas so arrays of objects and nested enums survive the conversion too.

    2. Broader fix — serialize the original schema instead of rebuilding it field-by-field, so no keyword gets silently dropped in the future. This class of bug is hard to catch precisely because the drop is silent.

    For a first PR I'd lean toward option 1 (small and easy to review), with option 2 as a possible follow-up if you agree it's worth it. Any preference before I open the PR?

  4. added a commit that references this issue on Oct 6, 2026
    a56645f
  5. hirematha commented on Oct 6, 2026

    @hirematha

    Hi @caps-xia, Thank you for reporting this issue and we appreciate you putting together a PR to fix it. I have successfully reproduced the issue you described. Both the issue and associated PR are now under review by the team. We will keep you updated and let you know if we need any additional information. Thank you.

  6. added 2 commits that reference this issue on Oct 8, 2026
    b5eb358
    7b1a5b8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions