🔗 Live Demo - Try it now!
Baseball Stats AI is an intelligent AI agent I built to explore how natural language processing can simplify baseball statistics queries. It enables users to ask questions in plain English about MLB pitching statistics and receive intelligent, conversational responses powered by AI.
This project bridges the gap between complex SQL databases and casual baseball fans, making statistical analysis faster, more intuitive, and more accessible through the power of edge computing and AI.
Ask questions in plain English like "Who had the lowest ERA in 2023?" and get instant answers.
Automatically converts natural language into accurate SQL queries using Workers AI.
Queries 56,000+ MLB pitching records (2018-2024) from D1 database with sub-second response times.
AI formats raw database results into natural, conversational responses.
Deployed on Cloudflare's global network with <50ms latency worldwide.
Clean and interactive interface built with Tailwind CSS and Inter font. Features auto-scroll, click-to-copy contact, and example queries.
No data collection, no authentication required. All queries are stateless.
- Cloudflare Workers — Serverless edge computing platform
- Workers AI (Llama 3.3-70B) — Natural language processing and SQL generation
- D1 Database — SQLite-based database with 56,000+ records
- TypeScript — Type-safe development
- Wrangler CLI — Deployment and development tool
- HTML5 — Structure of the web application
- TailwindCSS — Utility-first CSS framework for clean and responsive UI
- Vanilla JavaScript (ES6+) — Frontend logic and user interactions
- Inter Font — Professional typography from Google Fonts
- Lahman Baseball Database — Historical MLB statistics (1871-2024)
- License: CC BY-SA 4.0 — Open source baseball data
- Coverage: 2018-2024 — Focused on recent pitching statistics
User Query (Natural Language)
↓
Cloudflare Workers (TypeScript)
↓
Workers AI (Llama 3.3) → Generate SQL Query
↓
D1 Database (SQLite) → Execute Query
↓
Workers AI (Llama 3.3) → Format Response
↓
Natural Language Response
cf-ai-baseball/
├── workers/
│ └── agent.ts # Main application (backend + frontend)
├── data/
│ ├── People.csv # Player information
│ ├── pitching.csv # Pitching statistics
│ └── teams.csv # Team data
├── scripts/
│ └── seed_d1.ts # Database seeding script
├── wrangler.toml # Cloudflare configuration
├── package.json # Dependencies
├── tsconfig.json # TypeScript configuration
└── README.md
Try asking:
- "Who had the lowest ERA in 2023?"
- "Show me Washington Nationals pitchers with ERA under 3.50 in 2023"
- "Top 5 strikeout leaders for Seattle in 2019"
- "Summarize Justin Verlander's ERA by year"
- "How many wins did the Yankees have in 2024?"
- Integrated 3 Cloudflare services (Workers, AI, D1) seamlessly
- Natural language to SQL conversion using LLM
- Real-time database queries on 56,000+ records
- Intelligent fallback mechanisms for error handling
- Global edge deployment with <50ms latency
- Professional UI/UX with modern design patterns
- Response Time: ~1.5-2.5 seconds per query
- Global Latency: <50ms (North America), <100ms (Asia)
- Database Size: 56,000+ records
- Free Tier: 10,000 AI requests/day
# Install dependencies
npm install
# Deploy to Cloudflare
npm run deploy
# View real-time logs
npx wrangler tailCode: © 2025 Yu Lo. All rights reserved.
Data Source:
Lahman Baseball Database
✨ Building full-stack tools that blend natural language AI with real-world use cases like sports analytics
⚡ Powered by Cloudflare Workers | AI by Meta Llama 3.3 | Data by Lahman