top of page

Nutrition AI

A full-stack, multi-agent AI application that empowers users to seamlessly query the complex USDA Food Data Central database using natural language. The system autonomously translates user questions into secure SQL, calculates personalized macronutrient and micronutrient targets, and dynamically renders interactive data visualizations and clinical summaries on the fly.

Business question: Can a graph-based, multi-agent AI orchestration pipeline reliably translate natural language into complex database queries to provide accurate, hallucination-free nutritional analytics and personalized dietary tracking for non-technical users?

Technology stack: React, Plotly.js, Firebase Hosting, Python, FastAPI, Google Cloud Run, LangGraph, Google Vertex AI (Gemini 2.5 Pro), Google BigQuery.

Key Insights

​

  • Multi-Agent Orchestration Validation: The LangGraph pipeline successfully isolates complex reasoning tasks across four specialized nodes (Librarian, Data Retrieval, Visualizer, Summarizer), significantly reducing LLM hallucinations and preventing cascading system failures.

  • Dynamic Text-to-SQL Translation: The Librarian agent autonomously translates natural language queries into secure, precise Google BigQuery SQL statements, dynamically handling multi-ingredient comparisons (via OR statements) and strict numeric formatting constraints.

  • Resilient Visual Generation: The Visualizer dynamically configures Plotly charts based on retrieved data structures. Implementation of isolated error-handling ensures that visualization mapping errors gracefully default to raw data tables without crashing the downstream AI summary generation.

  • Zero-Latency Observability: The FastAPI backend utilizes asynchronous background tasks to silently log all user queries, AI responses, and system errors into an append-only BigQuery table, ensuring comprehensive analytics without adding latency to the front-end response times.

1. Data Source
  • Authoritative Nutritional Database: Data is sourced directly from the USDA Food Data Central, providing highly accurate and standardized profiles for macronutrients, micronutrients, and dietary reference intakes.

  • Cloud Data Warehouse Architecture: The data is hosted on Google BigQuery, structurally divided into a read-only USDA dataset for agent retrieval operations and a separate, append-only chat_logs table for application telemetry.

  • Core Nutritional Domains Analyzed: Includes detailed food descriptions, specific nutrient metric arrays, standardized unit measurements (e.g., mg, ug), and unique FDC identifiers for precise filtering and deduplication.

  • Automated Contextual Extraction: The LangGraph Checkpointer securely maintains conversational memory via Browser Local Storage, utilizing extracted user profile metrics to automatically calculate personalized macro and micro targets using the Mifflin-St Jeor equation.

2. Data Retrieval and Processing
 
  • Dynamic Data Extraction: Data is queried and processed directly from the USDA Food Data Central dataset hosted in Google BigQuery, orchestrated by a Python/FastAPI backend and the LangGraph multi-agent framework.

  • Autonomous SQL Generation: Natural language queries are processed by the Librarian Agent to construct secure, highly specific Text-to-SQL commands that map user intents to exact food descriptions, FDC IDs, and standardized nutrient metrics.

  • Automated Data Cleaning: Through the Data Retrieval node, raw database returns undergo robust cleaning, including universal deduplication, strict numeric extraction for amounts, and nutrient alias standardization to prevent visualization errors.

  • Contextual Dietary Workflows: The system merges retrieved food data with the user's specific physiological profile (maintained via the LangGraph checkpointer), executing real-time math to compare query results against personalized daily targets calculated via the Mifflin-St Jeor equation.

  • Multi-Ingredient Logic: Complex comparison workflows dynamically utilize SQL OR clauses, allowing side-by-side nutritional evaluations of specific foods rather than limiting users to broad categorical rankings.

3. Data Visualization
 
  • Autonomous UI Configuration: Visualizations are dynamically configured by the LangGraph Visualizer agent, which writes custom JSON plotting schemas that are rendered interactively on the client side using React and Plotly.js.

  • Visualizations generated for the application include:

  • Macronutrient Bar Charts: Horizontal bar charts displaying energy, proteins, fats, and carbohydrates, automatically sorted by a standardized physiological hierarchy and formatted with precise unit measurements.

  • Micronutrient Bar Charts: Visual distributions of vitamins and minerals, utilizing a custom sorting algorithm (e.g., sequentially from Vitamin A through K) for clear, clinical presentation.

  • Nutrient Composition Pie Charts: Interactive pie charts illustrating the proportional percentage breakdown of core macronutrients (Protein, Carbohydrates, Lipids) within queried food items.

  • Dynamic Data Tables: Responsive, structured tables that serve as both detailed data views and resilient system fallbacks; protected by isolated try/except logic, these ensure continuous UI stability and uninterrupted AI summary generation even if a primary chart fails.

  • Metric Cards: High-level, single-value data callouts designed for quick daily diary logging and immediate nutrient intake assessments.

Other projects

bottom of page