Skip to content

Conversation

@github-actions
Copy link
Contributor

Summary

Fixes the nutrition agent error handling to prevent hallucination of products when nutrition data is not available for specific pet types.

Root Cause Analysis

Based on the investigation results, the nutrition agent was hallucinating products because:

  • The nutrition service only has data for 6 pet types (cat, dog, lizard, snake, bird, hamster) but customers ask about 10+ other pets (rabbit, ferret, guinea pig, turtle, reptile, gecko, birds, bearded dragon, kitten, puppy)
  • When the nutrition service returns 404, the agent receives error messages but still fabricates product recommendations
  • The system prompt instructed the agent to "Always recommend the SPECIFIC PRODUCT NAMES provided" but when no products are provided (404 case), it generates fictional products instead of saying "we don't have information"

Changes Made

1. Updated Error Handling

  • Modified get_nutrition_data() to explicitly handle 404 responses with clear messaging: "We don't currently have nutrition information for [pet_type] in our database"
  • Added has_data flag to track when actual nutrition data is available vs. error states

2. Modified System Prompt

  • Updated system prompt to handle missing data gracefully instead of hallucinating
  • Added explicit instructions to NEVER fabricate product names, nutrition facts, or recommendations when data is not available
  • Changed from "Always recommend SPECIFIC PRODUCT NAMES" to "Only recommend SPECIFIC PRODUCT NAMES that are actually provided to you"

3. Updated Tool Functions

  • All nutrition tool functions (get_feeding_guidelines, get_dietary_restrictions, get_nutritional_supplements) now check has_data flag before providing recommendations
  • When no data is available, tools return the clear error message instead of attempting to provide recommendations

4. Enhanced Order Creation

  • create_order function now prevents order creation for unsupported pet types
  • Returns clear message when nutrition information is not available for the requested pet type

Impact

  • Eliminates hallucination of fictional products like "RabbitCare Premium Pellets"
  • Provides clear, honest responses when nutrition information is not available
  • Maintains functionality for supported pet types (cat, dog, lizard, snake, bird, hamster)
  • Improves customer experience by setting proper expectations

Testing

The changes ensure that:

  • ✅ Supported pet types continue to receive proper nutrition recommendations with real products
  • ✅ Unsupported pet types receive clear "we don't have information" messages
  • ✅ No fictional products are recommended when data is unavailable
  • ✅ Order creation is prevented for unsupported pet types

Fixes the issues identified in the investigation where 1,575 rabbit requests and 265 ferret requests were failing due to hallucinated product recommendations.

- Update error handling to explicitly state "We don't currently have nutrition information for [pet_type] in our database" for 404 responses
- Modify system prompt to handle missing data gracefully instead of hallucinating products
- Add has_data flag to prevent product recommendations when no data is available
- Update all tool functions to check data availability before providing recommendations
- Prevent order creation for unsupported pet types
@liustve liustve merged commit 3c78ba8 into main Nov 10, 2025
8 checks passed
liustve added a commit that referenced this pull request Nov 10, 2025
@liustve liustve deleted the fix/nutrition-agent-error-handling branch November 11, 2025 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants