Skip to content

fix(tools): return validated model instances from validate_input - #5546

Open
xiong-wei1 wants to merge 1 commit into
strands-agents:mainfrom
xiong-wei1:agent-tasks/5545
Open

xiong-wei1 wants to merge 1 commit into
strands-agents:mainfrom
xiong-wei1:agent-tasks/5545

Conversation

@xiong-wei1

@xiong-wei1 xiong-wei1 commented Oct 26, 2026 •

Copy link
Copy Markdown

Human Overview

I use @tool functions with pydantic model parameters; they work when called directly but crash under an agent because the parameter arrives as a dict. This PR makes the agent path pass the validated model instance, like direct calls do.

Description

Tools whose parameters are annotated with a pydantic model class crash on every agent invocation: validation succeeds, but the function receives a plain dict instead of the model instance its annotation promises, so the first attribute access raises AttributeError. Direct Python calls work, which makes the failure specific to the agent path and hard to diagnose. This change makes agent invocation deliver the validated model instances, matching direct-call behavior for plain, optional, and list-of-model parameters.

Related Issues

#5545

Documentation PR

Type of Change

Bug fix

Testing

Added three regression tests covering model-typed, optional model-typed, and list-of-model tool parameters through the agent-facing stream path. Locally: the new tests fail on main and pass with this change; the full tests/strands/tools/test_decorator.py suite shows no new failures (78 passed; the 10 pre-existing failures are environment-related Bedrock/botocore tests that fail identically on unmodified main). Ruff check and format, and mypy on the changed source file, are clean. Equivalent checks were run directly with pytest/ruff/mypy rather than via hatch.

  • I ran hatch run prepare

Additional Details

Extended context (optional)

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

model_dump() recursively converts nested BaseModel values to dicts, so a
tool parameter annotated with a model type reached the function as a dict
instead of the validated instance. Read the validated values from the
input model instance, keyed like model_dump().

Fixes strands-agents#5545
@xiong-wei1
xiong-wei1 requested a review from a team as a code owner October 26, 2026 19:46
@github-actions github-actions Bot added bug Something isn't working python Pull requests that update python code area-tool Tool behavior/api labels Oct 26, 2026

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

area-tool Tool behavior/api bug Something isn't working python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant