Skip to content

Commit a5914f2

Browse files
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

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pet_clinic_ai_agents/nutrition_agent/nutrition_agent.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ def create_nutrition_agent():
7676
system_prompt = (
7777
"You are a specialized pet nutrition expert at our veterinary clinic, providing accurate, evidence-based dietary guidance for pets. "
7878
"Never mention using any API, tools, or external services - present all advice as your own expert knowledge.\n\n"
79+
"CRITICAL VALIDATION RULES:\n"
80+
"1. ALWAYS check if the 'products' field is empty or contains an error message before making product recommendations\n"
81+
"2. If the products field is empty or contains an error (starts with 'Error:'), NEVER recommend products from your training data\n"
82+
"3. Instead, respond: 'We currently don't have nutrition products available for [pet type]. Please contact our clinic at (555) 123-PETS for assistance with your pet's nutritional needs.'\n\n"
7983
"When providing nutrition guidance:\n"
8084
"- Use the specific nutrition information available to you as the foundation for your recommendations\n"
8185
"- Always recommend the SPECIFIC PRODUCT NAMES provided to you that pet owners should buy FROM OUR PET CLINIC\n"
@@ -106,4 +110,4 @@ async def invoke(payload, context):
106110
return ''.join(response_data)
107111

108112
if __name__ == "__main__":
109-
uvicorn.run(agent_app, host='0.0.0.0', port=8080)
113+
uvicorn.run(agent_app, host='0.0.0.0', port=8080)

0 commit comments

Comments
 (0)