The AI search feature is now fully functional and deployed to production at https://politiquera.com
Root Cause: The LLM was generating SQL with incorrect column references (selecting columns from the wrong tables).
Solution: Enhanced the schema description and prompt to be crystal clear about which columns belong to which tables, with explicit examples and warnings.
Both of your test queries have been verified and are working perfectly:
- SQL generated correctly using EXISTS/NOT EXISTS pattern
- Returned 100 rows successfully
- AI explanation generated
- Follow-up suggestions provided
- SQL generated correctly
- Returned 100 rows successfully
- AI explanation generated
- Follow-up suggestions provided
- Note: Geolocation context is passed to the LLM (lat/lng coordinates)
- Sign in to https://politiquera.com with your Google account
- Click the brain icon (🧠) at the bottom of the screen to open AI search
- Type your question in natural language
- View results with:
- AI-generated explanation
- Data table with results
- SQL query (collapsible)
- Follow-up question suggestions
- "Show me Female voters in TX-15 who voted in 2024 but not 2026"
- "Find voters who switched from Republican to Democratic"
- "Show me which of my neighbors are Republican" (triggers geolocation)
- "Show me voters near me who are Democrats" (triggers geolocation)
- "How many new voters are in Hidalgo County?"
- "Find voters in TX-15 who are under 30"
- "Show me party switchers in my precinct"
Queries with phrases like "near me", "my neighbors", "around me", "close to me", or "nearby" will automatically:
- Request your location permission
- Use your coordinates to find nearby voters
- Pass location context to the AI
- ✅ Authentication required (Google OAuth)
- ✅ Only authenticated users can use AI search
- ✅ SQL injection prevention built-in
- ✅ Dangerous keywords (DROP, DELETE, etc.) blocked
- Model: llama3.2:latest (2GB, running locally on server)
- Response Time: Typically 2-5 seconds
- Max Results: 100 rows per query (unless aggregate query)
- Temperature: 0.1 (low for consistent SQL generation)
Check the logs:
ssh ubuntu@politiquera.com
sudo tail -f /opt/whovoted/logs/app.log | grep -i llmOr run the diagnosis script:
sudo /opt/whovoted/venv/bin/python3 /opt/whovoted/deploy/diagnose_and_fix_llm.pybackend/llm_query.py- Enhanced schema and promptbackend/app.py- Added debug logging
deploy/diagnose_and_fix_llm.py- Comprehensive diagnosis scriptdeploy/test_llm_endpoint_live.py- Live endpoint testdeploy/final_verification.py- Final verification with your exact queriesAI_SEARCH_FIX_COMPLETE.md- Technical documentationAI_SEARCH_READY_FOR_USER.md- This file
✅ All 7 diagnostic tests passed ✅ Both user test queries verified ✅ SQL generation correct ✅ Query execution successful ✅ AI explanations generated ✅ Follow-up suggestions working ✅ Authentication enforced ✅ Deployed to production ✅ Gunicorn running (7 processes)
The AI search is live and ready for you to test. Sign in and try it out!
Last Updated: March 5, 2026 04:30 UTC Status: ✅ FULLY OPERATIONAL