Skip to content

Update structured output docs to make tool use example more obvious #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
50 changes: 28 additions & 22 deletions docs/user-guide/concepts/agents/structured-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,34 @@ print(f"Age: {result.age}") # 30
print(f"Job: {result.occupation}") # "software engineer"
```

### Using Tools and Conversation History

Structured output can work with tools and conversation history, but the agent must be primed with that information before calling the `structured_output` function.

```python
from strands import Agent
from pydantic import BaseModel
from strands_tools import http_request

agent = Agent(tools=[http_request])

# Build up conversation context
agent("What do you know about Paris, France?")
agent("Can you check the weather there now?")

# Extract structured information with a prompt
class CityInfo(BaseModel):
city: str
country: str
weather: str

# Uses existing conversation context with a prompt
result = agent.structured_output(CityInfo, "Extract structured information about Paris")
print(result.city)
print(result.country)
print(result.weather)
```

### Multi-Modal Input

Extract structured information from prompts containing images, documents, and other content types:
Expand Down Expand Up @@ -112,28 +140,6 @@ result = agent.structured_output(
For a complete list of supported content types, please refer to the [API Reference](../../../api-reference/types.md#strands.types.content.ContentBlock).


### Using Conversation History

Structured output can work with existing conversation context:

```python
agent = Agent()

# Build up conversation context
agent("What do you know about Paris, France?")
agent("Tell me about the weather there in spring.")

# Extract structured information with a prompt
class CityInfo(BaseModel):
city: str
country: str
population: Optional[int] = None
climate: str

# Uses existing conversation context with a prompt
result = agent.structured_output(CityInfo, "Extract structured information about Paris")
```

### Complex Nested Models

Handle sophisticated data structures:
Expand Down