generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 420
Open
Labels
area-structured-outputRelated to the structured output apiRelated to the structured output apibugSomething isn't workingSomething isn't working
Description
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.8.0
Python Version
3.12.11
Operating System
macOS 15.6.1
Installation Method
pip
Steps to Reproduce
from strands import Agent, tool
from pydantic import BaseModel, Field
# Define a Pydantic model for the desired output structure
class UserInfo(BaseModel):
id: str = Field(description="A unique identifier for the user")
name: str = Field(description="The full name of the user")
age: int = Field(description="The age of the user in years", ge=0, le=150)
city: str = Field(description="The city where the user currently lives")
@tool
def generate_user_id() -> str:
"""Generate a unique user identifier
Creates a universally unique identifier
Returns:
str: A unique user identifier
"""
print("Generating user ID")
return "User_12345"
def main():
agent = Agent(
model="us.anthropic.claude-sonnet-4-20250514-v1:0", tools=[generate_user_id]
)
print(agent.model.config)
# Use structured_output to guide the agent to return a UserInfo object
user_data = agent.structured_output(
prompt="Generate information about random users. Use generate_user_id() tool to generate user identifier",
output_model=UserInfo,
)
# user_data will be an instance of UserInfo, which can be easily converted to JSON
print(user_data.model_dump_json())
if __name__ == "__main__":
main()
Expected Behavior
We should see tool called and "User_12345" is used for UserID.
Actual Behavior
Random ID or "" is generated
Additional Context
No response
Possible Solution
No response
Related Issues
No response
Metadata
Metadata
Assignees
Labels
area-structured-outputRelated to the structured output apiRelated to the structured output apibugSomething isn't workingSomething isn't working