Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/strands/tools/structured_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def convert_pydantic_to_tool_spec(
Returns:
ToolSpec: Dict containing the Bedrock tool specification
"""
name = model.__name__
name = f"{model.__name__}OutputStructurer"
Copy link
Member

Choose a reason for hiding this comment

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

I dont really like having every tool name sent to the model to have this appended to it.

If the issue is the communication with the customer, can we update our logs to better communicate that?

Let me help review and schedule your order using the available tools.

Let me determine which groceries to buy
Generating Structured Output with Tool: Grocery

Copy link
Member Author

Choose a reason for hiding this comment

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

I think Generating Structured Output with Tool: Grocery is the confusing part. What is a Grocery tool?


# Get the JSON schema
input_schema = model.model_json_schema()
Expand All @@ -300,7 +300,7 @@ def convert_pydantic_to_tool_spec(
# Construct the tool specification
return ToolSpec(
name=name,
description=model_description or f"{name} structured output tool",
description=model_description or f"{model.__name__} structured output tool",
inputSchema={"json": final_schema},
)

Expand Down
2 changes: 1 addition & 1 deletion tests/strands/models/test_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ async def test_structured_output(anthropic_client, model, test_output_model_cls,
return_value={
"type": "content_block_start",
"index": 0,
"content_block": {"type": "tool_use", "id": "123", "name": "TestOutputModel"},
"content_block": {"type": "tool_use", "id": "123", "name": "TestOutputModelOutputStructurer"},
}
),
),
Expand Down
6 changes: 5 additions & 1 deletion tests/strands/models/test_bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,11 @@ async def test_structured_output(bedrock_client, model, test_output_model_cls, a
bedrock_client.converse_stream.return_value = {
"stream": [
{"messageStart": {"role": "assistant"}},
{"contentBlockStart": {"start": {"toolUse": {"toolUseId": "123", "name": "TestOutputModel"}}}},
{
"contentBlockStart": {
"start": {"toolUse": {"toolUseId": "123", "name": "TestOutputModelOutputStructurer"}}
}
},
{"contentBlockDelta": {"delta": {"toolUse": {"input": '{"name": "John", "age": 30}'}}}},
{"contentBlockStop": {}},
{"messageStop": {"stopReason": "tool_use"}},
Expand Down
10 changes: 5 additions & 5 deletions tests/strands/tools/test_structured_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_convert_pydantic_to_tool_spec_basic():
tool_spec = convert_pydantic_to_tool_spec(User)

expected_spec = {
"name": "User",
"name": "UserOutputStructurer",
"description": "User model with name and age.",
"inputSchema": {
"json": {
Expand Down Expand Up @@ -73,7 +73,7 @@ def test_convert_pydantic_to_tool_spec_complex():
tool_spec = convert_pydantic_to_tool_spec(ListOfUsersWithPlanet)

expected_spec = {
"name": "ListOfUsersWithPlanet",
"name": "ListOfUsersWithPlanetOutputStructurer",
"description": "List of users model with planet.",
"inputSchema": {
"json": {
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_convert_pydantic_to_tool_spec_multiple_same_type():
tool_spec = convert_pydantic_to_tool_spec(TwoUsersWithPlanet)

expected_spec = {
"name": "TwoUsersWithPlanet",
"name": "TwoUsersWithPlanetOutputStructurer",
"description": "Two users model with planet.",
"inputSchema": {
"json": {
Expand Down Expand Up @@ -286,7 +286,7 @@ class Person(BaseModel):
"type": "object",
}
},
"name": "Person",
"name": "PersonOutputStructurer",
}
assert tool_spec == expected_spec

Expand Down Expand Up @@ -340,6 +340,6 @@ class Person(BaseModel):
"type": "object",
}
},
"name": "Person",
"name": "PersonOutputStructurer",
}
assert tool_spec == expected_spec
Loading