Skip to content

SWF(bug): reject named tool_choice not among declared tools - #52

Merged
maplepaladin73 merged 1 commit into
mainfrom
devin/1795371427-named-tool-choice
Nov 22, 2026
Merged

maplepaladin73 merged 1 commit into
mainfrom
devin/1795371427-named-tool-choice

Conversation

@maplepaladin73

@maplepaladin73 maplepaladin73 commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

A chat request whose tool_choice names a function that isn't in tools (or with no tools at all) is now rejected with a 400 (param: "tool_choice") instead of being silently accepted.

Root cause: validate_input in crates/spark-server/src/api/chat_phases.rs only matched ToolChoice::Mode (auto/none/required), so ToolChoice::Specific { function } skipped validation entirely. The new guard checks the name against the declared tool.function.names. Anthropic {type:"tool", name} converts to the same ToolChoice::Specific and runs through chat_completions_inner → validate_input, so it is covered by the same check.

Test plan

Failing run on unfixed code (regression test added first; captured before the rebase onto #51, with the stray attribute removed locally):

test api::chat_phases::tests::named_tool_choice_accepts_declared_function ... ok
test api::chat_phases::tests::named_tool_choice_rejects_undeclared_function ... FAILED

undeclared tool must be rejected: ()

test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 3212 filtered out; finished in 0.00s

Passing run with the fix:

test api::chat_phases::tests::named_tool_choice_accepts_declared_function ... ok
test api::chat_phases::tests::named_tool_choice_rejects_undeclared_function ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 3213 filtered out; finished in 0.00s

Full spark test binary on the rebased branch:

test result: ok. 3201 passed; 0 failed; 14 ignored; 0 measured; 0 filtered out; finished in 21.15s

The rejection test covers omitted tools, empty tools, and a non-matching tool; the acceptance test covers a declared name among several. Existing Anthropic conversion tests: 11 passed.

Try it (after bash scripts/ci_gpu_stubs.sh):

ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-server --bin spark named_tool_choice

Blueprint lint (cargo fmt --all -- --check && cargo clippy --workspace --tests && check-license-headers.sh && typos):

    Finished `dev` profile [unoptimized + debuginfo] target(s) in 49.69s
INFO Totally checked 4275 files, valid: 4261, invalid: 0, ignored: 14, fixed: 0
Lint exit status: 0
  • cargo fmt --all -- --check
  • clippy --workspace --tests
  • bash scripts/check-license-headers.sh
  • Tested against a real model / hardware: not run
  • Added tests

Notes for reviewers


Software Factory opened this PR for Robert
Implemented in session Validate named tool_choice against declared tools
Review with Devin · Open in Devin Desktop


@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1795371427-named-tool-choice branch from c477a44 to 92223a4 Compare November 22, 2026 18:29
@maplepaladin73
maplepaladin73 merged commit 4493447 into main Nov 22, 2026
1 check passed
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.

1 participant