Skip to content

fix(llms): coerce dict tool_search config instead of silently disabling it - #8738

Open
heyseere wants to merge 1 commit into
crewAIInc:mainfrom
heyseere:fix/anthropic-tool-search-dict
Open

heyseere wants to merge 1 commit into
crewAIInc:mainfrom
heyseere:fix/anthropic-tool-search-dict

Conversation

@heyseere

@heyseere heyseere commented Oct 28, 2026 •

Copy link
Copy Markdown

Related issue

Fixes #8734

Summary

The Anthropic pre-validator discarded any tool_search value that was not True or an AnthropicToolSearchConfig instance — including plain dicts, which is exactly what YAML/JSON agent configs produce when the llm: block is passed through LLM(**value). Result: tool_search: {type: regex} silently disabled tool search instead of coercing.

This keeps special-casing only True (default variant) and False/None (disabled) and lets the pydantic field (annotated AnthropicToolSearchConfig | None) coerce and validate dict inputs, so invalid values now fail loudly instead of silently disabling.

Verification

  • Tests added or updated for the changed behavior
  • Relevant tests and quality checks pass locally

lib/crewai/tests/llms/anthropic/test_anthropic.py (105 passed): new tests cover dict coercion, tool_search=False → None, and loud failure on an invalid dict. ruff check clean on changed files.

Disclosure: this PR was produced with AI assistance (ZCode agent) and human-reviewed — please apply the llm-generated label.

Additional context

None

From ZCode


Note

Low Risk
Narrow change to Anthropic LLM config normalization with regression tests; behavior improves YAML configs without touching auth or runtime tool execution paths.

Overview
Fixes Anthropic tool_search handling when the value comes from YAML/JSON agent configs as a plain dict (e.g. {"type": "regex"}).

The _normalize_anthropic_fields pre-validator no longer clears every non-True, non-config value to None. It still maps tool_search=True to the default AnthropicToolSearchConfig and tool_search=False to None, but leaves dicts and existing config instances for the Pydantic field to coerce and validate. That restores server-side tool search for configured agents and makes bad type values fail at construction instead of silently turning search off.

Tests cover dict coercion, explicit False, and invalid dict validation.

Reviewed by Cursor Bugbot for commit 9a249c9. Bugbot is set up for automated code reviews on this repo. Configure here.

@strix-security

strix-security Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Strix Security Review

Warning

This pull request has 23 commits after the last Strix review (58c63bf). Strix has not reviewed these changes.
Automatic review on push is off for this repository. To review the latest changes, tag @strix-security in a comment, or turn on re-review on push.

✅ No open security findings.

PR summary: This PR fixes Anthropic LLM config handling so a `tool_search` value supplied as a dict (as YAML/JSON agent configs produce) is coerced into `AnthropicToolSearchConfig` by the pydantic field instead of being silently discarded; only `True` (default variant) and `False`/`None` (disabled) remain special-cased. It also adds tests for dict coercion, `False` disabling, and failure on invalid dicts.

Review summary

No security issues found. The change narrows a pre-validator so only True and False are special-cased and all other tool_search values reach pydantic for coercion/validation. The value is operator-supplied LLM configuration, and its only consumer restricts output to a fixed Literal["regex", "bm25"] mapped to two constant tool-type strings, so no attacker-controlled data reaches the Anthropic request body, and invalid values now fail loudly rather than silently disabling the feature.

Review 1 on this PR · 58c63bf · requested Oct 28 16:06 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings

@heyseere
heyseere force-pushed the fix/anthropic-tool-search-dict branch 2 times, most recently from 7b044b0 to 1d9939b Compare October 29, 2026 15:42
@heyseere

Copy link
Copy Markdown
Author

Friendly ping for a review when you have a moment. All bot checks are green and the PR is mergeable; happy to adjust anything.

@heyseere
heyseere force-pushed the fix/anthropic-tool-search-dict branch from 1d9939b to 9a249c9 Compare November 1, 2026 09:58

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.

[BUG] Anthropic tool_search given as a dict is silently disabled

1 participant