This site is not affiliated with or endorsed by Vercel, Inc. Read the docs, then deploy or run each experiment yourself.
AI

Schema from Sample Lab

Paste JSON or CSV - TypeScript types and Zod schema strings you can download.

Run this experiment yourself

Demos are not embedded on this site. Deploy a standalone copy on Vercel or run the experiment app locally.

Local development

cd apps/experiments/schema-from-sample-lab
pnpm install
pnpm dev

Then open http://localhost:3010.

This is an experimental demo. Use it as a starting point for your own projects.

Schema from Sample Lab infers TypeScript types and Zod schemas from a JSON or CSV paste. detectSampleKind hints the prompt; the model returns code strings you can download as types.ts / schema.ts. No AI keys - 503.

Features

  • JSON or CSV samples – one-click loaders.
  • Dual code output – TypeScript + Zod strings.
  • Notes – assumptions (optional fields, unions).
  • Download buttons – save each string.
  • Honest unavailable state.

Server Reference

POST /api/schema

{ "sample": "{ ... }" }

Success (200)

{
  "typescript": "export type User = { id: string; ... }",
  "zod": "export const UserSchema = z.object({ ... })",
  "notes": ["roles is string[]"],
  "detectedKind": "json",
  "provider": "ai-gateway"
}
StatusCause
503No AI provider
400Empty sample

Implementation Details

detectSampleKind and clampSchema are pure helpers in logic.ts (unit tested).

Use Cases

  • Bootstrap Zod from API fixtures.
  • Teach sample - schema composition.
  • CSV column typing drafts.

Limitations

  • Sparse samples produce weak types.
  • Does not validate generated code by compiling it.
  • No auth / rate limits.

Use in your project

Reuse the dual string schema from app/api/schema/route.ts.

Deployment

Deploy on Vercel

Local Development

cd apps/experiments/schema-from-sample-lab
pnpm install
pnpm dev

Configuration

VariableRequiredPurpose
AI_GATEWAY_API_KEYYes (or OPENAI_API_KEY)Preferred provider
OPENAI_API_KEYNoFallback
AI_MODELNoModel override

Vercel / Next.js Features Used

  • AI SDK generateObject
  • Vercel AI Gateway
  • Route Handlers
  • Zod

Next Steps

On this page