Files
Priceflow/app
Claude 0529c885d3 fix: Improve AI price digit recognition to avoid 1.99/9.99 confusion
**Problem:**
AI was misreading prices: "1,99 €" detected as "9,99 €" with 90% confidence.
This is a critical OCR error where similar-looking digits (1, 7, 8, 9) are confused.
The model google/gemini-2.5-flash-lite made basic digit recognition mistakes.

**Root Cause:**
- AI vision models can confuse visually similar digits
- No specific instructions in prompt to verify digit accuracy
- No validation that detected price matches text context
- Model may be too lightweight for reliable OCR

**Solution: Three-Part Fix**

1. **Enhanced Prompt with Digit Verification** (ai_schema.py:145-149)
   - Added "CRITICAL - Read digits carefully" section
   - Explicit warning: "1,99 €" is NOT "9,99 €"
   - Instructions to double-check digits 1, 7, 8, 9 (visually similar)
   - Context check: Small prices (< 5€) are common
   - Verify price makes sense for product type

2. **More Examples in Prompt** (ai_schema.py:152-153)
   - Added: "1,99 €" -> 1.99 (NOT 9.99)
   - Added: "0,99 €" -> 0.99 (NOT 9.99)
   - Reinforces correct parsing of small prices

3. **Price Extraction Logging** (ai_service.py:349-355)
   - Extract ALL prices from text with regex: \d+[,\.]\d{2}\s*€
   - Log first 10 prices found: ["1,99 €", "2,99 €", ...]
   - Allows debugging: Is correct price in text?
   - Logs warning if NO prices found in text

4. **Debug Logs to INFO** (ai_service.py:347, 361)
   - Changed logger.debug → logger.info for text/prompt preview
   - Now visible in production logs for diagnosis

**Expected Improvement:**
- AI should now pay closer attention to digit shapes
- Lower confidence (0.5-0.7) if digits are unclear
- Better accuracy for small prices (0,99 - 4,99)
- Logs will show if problem is in text extraction or AI vision

**Testing:**
After restart, logs will show:
```
INFO - Cleaned text preview: 'Lutin de Noël 1,99 € Ajouter...'
INFO - Prices found in text: ['1,99 €', '2,99 €']
INFO - AI Response: {"price": 1.99, "price_confidence": 0.85}
```

If AI still returns wrong price but text has correct price,
then model is insufficient and should be upgraded to:
- google/gemini-2.0-flash-exp
- anthropic/claude-3-haiku
- openai/gpt-4o-mini
2025-11-29 23:36:47 +00:00
..
2025-11-22 10:01:25 +01:00
2025-11-22 10:01:25 +01:00
2025-11-22 10:01:25 +01:00
2025-11-22 10:01:25 +01:00