Skip to content

[BUG] @tool emits PydanticJsonSchemaWarning for Field(default_factory=list) #1914

@tealgreen0503

Description

@tealgreen0503

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

1.30.0

Python Version

3.11.x

Operating System

macOS 15.7

Installation Method

pip

Steps to Reproduce

from pydantic import Field
from strands import Agent, tool

@tool
def example(
    items: list[str] = Field(default_factory=list, description="items"),
) -> int:
    """Example tool."""
    return len(items)

Agent(tools=[example])
# PydanticJsonSchemaWarning: Default value annotation=NoneType required=False default_factory=list description='items' is not JSON serializable; excluding default from JSON schema [non-serializable-default]

Expected Behavior

No warning should be emitted. default_factory=list should be handled correctly when Strands builds the tool input schema.

Actual Behavior

Strands emits a Pydantic warning while generating the tool schema:

PydanticJsonSchemaWarning: Default value ... default_factory=list ... is not JSON serializable; excluding default from JSON schema

This looks like the decorator rebuilds the field as Field(default=<FieldInfo>), so Pydantic sees a non-serializable default.

Additional Context

I could not find an issue for this exact warning, but it looks related to the custom tool-validation/schema path discussed in #1246 and #917. It also seems similar in spirit to #337, but this case is about function-tool parameters using Field(default_factory=...).

Possible Solution

If a parameter default is already a Pydantic FieldInfo, preserve it instead of wrapping it again in Field(default=param_default, ...).

Related Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions