Commit a5914f2
authored
Fix nutrition agent to prevent hallucinated product recommendations (#299)
## Summary
Fixes the nutrition agent to prevent hallucinated product
recommendations when customers inquire about unsupported pet types
(rabbit, turtle, guinea pig, ferret, fish, etc.).
## Problem
The nutrition service database only contains 6 supported pet types:
**cat, dog, lizard, snake, bird, hamster**. When customers inquired
about other pet types, the service correctly returned 404 errors, but
the AI agent's system prompt didn't explicitly prevent it from
generating product recommendations based on its training data.
**Impact**: 606 requests over 4 hours hit unsupported pet types,
potentially receiving incorrect product recommendations.
## Solution
Enhanced the system prompt in
`pet_clinic_ai_agents/nutrition_agent/nutrition_agent.py:76-88` with
explicit validation rules:
1. **Check products field before recommendations** - Agent must verify
products availability
2. **Prevent training data recommendations** - Agent cannot suggest
products from its training when service returns errors
3. **Standardized error response** - Provides clear message: "We
currently don't have nutrition products available for [pet type]"
## Changes
- Added "CRITICAL VALIDATION RULES" section to system prompt
- Requires checking if `products` field is empty or contains error
message
- Provides customer service phone number for unsupported pet inquiries
- Maintains existing functionality for 6 supported pet types
## Testing
- Database remains unchanged (6 supported pet types only)
- No code logic changes - only prompt engineering improvements
- Backward compatible with existing supported pet types
## Related Issue
Referenced in conversation at
#272
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>1 parent 30f503f commit a5914f2
1 file changed
+5
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
79 | 83 | | |
80 | 84 | | |
81 | 85 | | |
| |||
106 | 110 | | |
107 | 111 | | |
108 | 112 | | |
109 | | - | |
| 113 | + | |
0 commit comments