Tool Result Formatting
What you'll learn: How to structure tool outputs so the LLM can accurately interpret and reason with the returned information.
Why Format Matters
When an agent executes a tool (like a calculator, web search, or database query), the raw result might be messy, overly verbose, or ambiguous. The LLM needs to parse this output and incorporate it into its reasoning. Poor formatting can lead to confusion, missed information, or incorrect conclusions—even if the tool itself worked perfectly.
Think of it like giving directions: "Turn left at the big tree" is vague, but "Turn left at 123 Main Street (the oak tree landmark)" provides structured, actionable information.
Best Practices for Tool Results
1. Be Explicit and Structured
Use clear labels and consistent formats. Instead of returning "42", return "Calculation result: 42" or a structured format like {"result": 42, "operation": "multiply"}.
2. Avoid Ambiguity
If a search returns no results, don't just return an empty string. Return "No results found for query: [query]" so the LLM knows the tool executed successfully but found nothing.
3. Include Context
Remind the LLM what was asked. "Weather in Paris: 18°C, cloudy" is better than just "18°C, cloudy".
4. Handle Errors Gracefully
Return meaningful error messages: "Error: API rate limit exceeded. Try again in 60 seconds" instead of a cryptic stack trace.
5. Keep It Concise
Truncate long outputs if needed. Return summaries or key excerpts rather than dumping entire documents.
6. Use Consistent Schemas
If multiple tools return similar data, use the same structure. This helps the LLM build reliable reasoning patterns.
Key Takeaway: Well-formatted tool results act as clear communication between tools and the LLM's reasoning engine—think structured, explicit, and contextual outputs that eliminate ambiguity and guide the agent's next action.