Observation Formatting and Parsing
What you'll learn: How to structure tool outputs as observations and parse them so the ReAct agent can reason about what happened next.
The Challenge of Tool Outputs
When your ReAct agent calls a tool (like a calculator, search API, or database query), the tool returns raw data. This output needs to be transformed into a clean, structured observation that the language model can understand and reason about in its next step.
Think of it like a scientist reading instrument readings: the raw voltage numbers mean nothing until they're formatted as "Temperature: 98.6°F" with appropriate units and context.
Formatting Observations
After executing an action, wrap the result in a consistent format:
Observation: [Tool output goes here]
This simple wrapper signals to the model that the previous action has completed and here's what came back. The format should be:
- Consistent: Always use the same prefix ("Observation:") so the model knows what to expect
- Clean: Remove unnecessary noise, error codes, or implementation details
- Contextual: Include just enough information for reasoning, not raw JSON dumps
For example, a search tool might return 50 fields, but you format the observation to show only the title, snippet, and URL.
Parsing Observations for Next Steps
The agent must extract relevant information from observations to inform its next reasoning step. This often means:
- Identifying key facts or values in the observation
- Checking for errors or empty results
- Determining if the goal is achieved or more actions are needed
The parsing happens implicitly through prompting—you guide the model to look for specific patterns in observations and respond accordingly.
Key Takeaway: Observations are the formatted bridge between messy tool outputs and clean language model reasoning—structure them consistently and concisely to keep the ReAct loop effective.