Fix receipt scanner AI response parsing #11
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/receipt-scanner-parsing"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes the receipt scanner that was failing to populate form fields after AI processing.
Problem
The receipt scanner AI was working correctly but the form wasn't being populated. Looking at the console output, the Firebase AI SDK returns responses in a different format than the standard Gemini SDK:
The code was expecting
result.response.text()but the actual structure wraps the response in telemetry events.Changes
1. Add Firebase AI response format detection
gen_ai.choiceevent and extract text frommessage.content[0].text2. Add "beverages" category to AI prompt
Testing
The user uploaded a Food Lion receipt with:
The AI successfully parsed it but the form didn't populate. With this fix, the response will now be properly extracted and the form will auto-fill.
Result
✅ Receipt scanner now works with Firebase AI SDK
✅ Handles both Firebase AI and standard Gemini response formats
✅ Better error messages for debugging
✅ Added beverages category for drinks/ingredients
The Firebase AI SDK returns responses in a different format than the standard Gemini SDK. It wraps responses in telemetry events with this structure: [ { "event.name": "gen_ai.choice", "message": { "content": [{"text": "..."}] } } ] This was causing the scanner to fail silently - the AI was working correctly but the response wasn't being parsed. Changes: - Add response format detection to handle both Firebase AI and standard Gemini formats - Extract text from telemetry events when present - Add "beverages" category to AI prompt (for lemonade, juices, etc.) - Add better error logging for unexpected response formats Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>