VercelLogotypeVercelLogotype
LoginSign Up

OSS Data Analyst Agent - Reference Architecture

Reference architecture for a text-to-SQL agent built with the AI SDK.

DeployView Demo

OSS Data Analyst

An AI data analyst agent that explores a semantic layer in a sandbox environment to answer natural language questions with SQL.

Overview

OSS Data Analyst uses a sandboxed exploration approach: instead of hardcoding schema knowledge into prompts, the agent is given shell access to a sandbox containing your semantic layer files. It discovers the schema dynamically using cat, grep, and ls commands, then builds and executes SQL queries based on what it finds.

This architecture means the agent can:

  • Adapt to any schema without prompt changes
  • Explore relationships between entities naturally
  • Handle schema updates without redeployment
  • Reason about data the same way a human analyst would

How It Works

  1. Sandbox Creation - A Vercel Sandbox is spun up and populated with your semantic layer YAML files
  2. Schema Exploration - The agent uses shell commands to browse the catalog and entity definitions
  3. Query Building - Based on discovered schema, the agent constructs SQL queries
  4. Execution - Queries run against your SQLite database
  5. Reporting - Results are formatted with a narrative explanation
User Question
↓
┌─────────────────────────────────────┐
│ Vercel Sandbox │
│ ┌─────────────────────────────┐ │
│ │ semantic/ │ │
│ │ ├── catalog.yml │ │
│ │ └── entities/ │ │
│ │ ├── companies.yml │ │
│ │ ├── people.yml │ │
│ │ └── accounts.yml │ │
│ └─────────────────────────────┘ │
│ │
│ Agent explores with: │
│ • cat semantic/catalog.yml │
│ • grep -r "keyword" semantic/ │
│ • cat semantic/entities/*.yml │
└─────────────────────────────────────┘
↓
SQL Query → Database → Results → Narrative

Quick Start

Prerequisites

  • Node.js 20+
  • pnpm
  • Vercel AI Gateway API key

Installation

git clone https://github.com/vercel-labs/oss-data-analyst.git
cd oss-data-analyst
pnpm install

Configuration

cp env.local.example .env.local

Add your Vercel AI Gateway key to .env.local.

Initialize Database

pnpm initDatabase

Creates a SQLite database with sample data (Companies, People, Accounts).

Run

pnpm dev

Open http://localhost:3000

Semantic Layer

The semantic layer lives in src/semantic/ and defines your data model:

src/semantic/
├── catalog.yml # Entity index with descriptions
└── entities/
├── companies.yml # Company entity definition
├── people.yml # People entity definition
└── accounts.yml # Accounts entity definition

Each entity YAML includes:

  • sql_table_name - The underlying table
  • fields - Available columns with SQL expressions
  • joins - Relationships to other entities
  • Example questions the entity can answer

The agent reads these files at runtime to understand your schema.

Example Questions

  • "How many companies are in the Technology industry?"
  • "What is the average salary by department?"
  • "Show me the top 5 accounts by monthly value"
  • "Which companies have the most employees?"

Architecture

Stack: Next.js, Vercel AI SDK, Vercel Sandbox, SQLite

Key Files:

  • src/lib/agent.ts - Agent definition and system prompt
  • src/lib/tools/sandbox.ts - Sandbox creation with semantic files
  • src/lib/tools/shell.ts - Shell command tool for exploration
  • src/lib/tools/execute-sqlite.ts - SQL execution tool

Adding Your Own Schema

  1. Add entity YAML files to src/semantic/entities/
  2. Update src/semantic/catalog.yml with the new entity
  3. The agent will automatically discover and use the new schema

No code changes required—the sandbox approach means schema changes are picked up at runtime.

Troubleshooting

Database Not Found

pnpm initDatabase

Build Errors

pnpm type-check
GitHub Repovercel-labs/oss-data-analyst
LicenseView License
Use Cases
AI
Stack
Next.js
Tailwind

Related Templates

Get Started

  • Templates
  • Supported frameworks
  • Marketplace
  • Domains

Build

  • Next.js on Vercel
  • Turborepo
  • v0

Scale

  • Content delivery network
  • Fluid compute
  • CI/CD
  • Observability
  • AI GatewayNew
  • Vercel AgentNew

Secure

  • Platform security
  • Web Application Firewall
  • Bot management
  • BotID
  • SandboxNew

Resources

  • Pricing
  • Customers
  • Enterprise
  • Articles
  • Startups
  • Solution partners

Learn

  • Docs
  • Blog
  • Changelog
  • Knowledge Base
  • Academy
  • Community

Frameworks

  • Next.js
  • Nuxt
  • Svelte
  • Nitro
  • Turbo

SDKs

  • AI SDK
  • Workflow SDKNew
  • Flags SDK
  • Chat SDK
  • Streamdown AINew

Use Cases

  • Composable commerce
  • Multi-tenant platforms
  • Web apps
  • Marketing sites
  • Platform engineers
  • Design engineers

Company

  • About
  • Careers
  • Help
  • Press
  • Legal
  • Privacy Policy

Community

  • Open source program
  • Events
  • Shipped on Vercel
  • GitHub
  • LinkedIn
  • X
  • YouTube

Loading status…

Select a display theme:
    • AI Cloud
      • AI Gateway

        One endpoint, all your models

      • Sandbox

        Isolated, safe code execution

      • Vercel Agent

        An agent that knows your stack

      • AI SDK

        The AI Toolkit for TypeScript

      • v0

        Build applications with AI

    • Core Platform
      • CI/CD

        Helping teams ship 6× faster

      • Content Delivery

        Fast, scalable, and reliable

      • Fluid Compute

        Servers, in serverless form

      • Workflow

        Long-running workflows at scale

      • Observability

        Trace every step

    • Security
      • Bot Management

        Scalable bot protection

      • BotID

        Invisible CAPTCHA

      • Platform Security

        DDoS Protection, Firewall

      • Web Application Firewall

        Granular, custom protection

    • Company
      • Customers

        Trusted by the best teams

      • Blog

        The latest posts and changes

      • Changelog

        See what shipped

      • Press

        Read the latest news

      • Events

        Join us at an event

    • Learn
      • Docs

        Vercel documentation

      • Academy

        Linear courses to level up

      • Knowledge Base

        Find help quickly

      • Community

        Join the conversation

    • Open Source
      • Next.js

        The native Next.js platform

      • Nuxt

        The progressive web framework

      • Svelte

        The web’s efficient UI framework

      • Turborepo

        Speed with Enterprise scale

    • Use Cases
      • AI Apps

        Deploy at the speed of AI

      • Composable Commerce

        Power storefronts that convert

      • Marketing Sites

        Launch campaigns fast

      • Multi-tenant Platforms

        Scale apps with one codebase

      • Web Apps

        Ship features, not infrastructure

    • Tools
      • Marketplace

        Extend and automate workflows

      • Templates

        Jumpstart app development

      • Partner Finder

        Get help from solution partners

    • Users
      • Platform Engineers

        Automate away repetition

      • Design Engineers

        Deploy for every idea

  • Enterprise
  • Pricing
Log InContact
Sign Up
Sign Up
DeployView Demo
AI Gateway

One endpoint, all your models

Sandbox

Isolated, safe code execution

Vercel Agent

An agent that knows your stack

AI SDK

The AI Toolkit for TypeScript

v0

Build applications with AI

CI/CD

Helping teams ship 6× faster

Content Delivery

Fast, scalable, and reliable

Fluid Compute

Servers, in serverless form

Workflow

Long-running workflows at scale

Observability

Trace every step

Bot Management

Scalable bot protection

BotID

Invisible CAPTCHA

Platform Security

DDoS Protection, Firewall

Web Application Firewall

Granular, custom protection

Customers

Trusted by the best teams

Blog

The latest posts and changes

Changelog

See what shipped

Press

Read the latest news

Events

Join us at an event

Docs

Vercel documentation

Academy

Linear courses to level up

Knowledge Base

Find help quickly

Community

Join the conversation

Next.js

The native Next.js platform

Nuxt

The progressive web framework

Svelte

The web’s efficient UI framework

Turborepo

Speed with Enterprise scale

AI Apps

Deploy at the speed of AI

Composable Commerce

Power storefronts that convert

Marketing Sites

Launch campaigns fast

Multi-tenant Platforms

Scale apps with one codebase

Web Apps

Ship features, not infrastructure

Marketplace

Extend and automate workflows

Templates

Jumpstart app development

Partner Finder

Get help from solution partners

Platform Engineers

Automate away repetition

Design Engineers

Deploy for every idea