SVG Studio: building a conversational SVG editor

SVG Studio lets users create icons and illustrations from a written request, then refine them through conversation. I built the application across the frontend, backend and AI workflow, including saved conversations, progressive previews, reference retrieval and evaluation tooling.

Personal project · Full-stack development and AI engineering

Stack: TypeScript, React, Next.js, Vercel AI SDK, OpenAI API, Neon PostgreSQL, pgvector, Drizzle ORM, Zod, Clerk, Braintrust, Tavily, Sharp, Saxes

Making generation work as an application

The main challenge was handling what happens between a request and a usable result. A model can produce incomplete markup, invalid content or an edit that does not satisfy the request. Users also need understandable progress, safe previews and a way to continue after failure.

The server loads the authenticated user's conversation and checks the request before drawing begins. A bounded agent can read the current SVG, propose a complete replacement, validate it and repair validation failures. The application independently validates the accepted result and saves it before reporting success.

Semantic routing with OpenAI Decisions API

I separated request classification from artwork generation using OpenAI Decisions API through Vercel AI SDK. One call evaluates scope, content policy and reply language against bounded conversation context. Application code validates the answers and routes to generation, clarification, a localized reply or rejection. Input moderation runs first; retrieval and drawing begin only after approval. Invalid classifier responses, provider failures and timeouts block generation.

This implements semantic routing and fail-closed policy enforcement. The current integration uses categorical choices; confidence-based thresholds and classifier calibration are not implemented.

Guardrails and safe streaming previews

Raw streamed SVG is incomplete and untrusted. I built parser-based snapshots at completed XML element boundaries, then validated those snapshots before rendering them as image Blob URLs. The interface separates temporary drafts from completed artwork and retains the previous result when generation fails.

Hybrid RAG: embeddings, pgvector and reciprocal rank fusion

Users can upload SVG references into private collections. The indexing pipeline validates and renders each asset, generates a visual description and embeds searchable text. Retrieval combines pgvector cosine similarity with PostgreSQL full-text search using reciprocal rank fusion. A limited number of complete SVG references then supplies context to the drawing agent.

I also exposed retrieval evidence so the selected references and their rankings can be inspected. Ownership checks apply throughout indexing, retrieval and saved conversations. Reference content is treated as untrusted context.

LLM-as-a-judge and deterministic evaluations with Braintrust

A valid SVG can still be a poor answer. I built separate evaluation checks for successful completion, SVG safety and tool behavior, with an optional vision-based LLM-as-a-judge for visible prompt requirements. Braintrust runs the evaluation experiments, with optional uploads and AI SDK telemetry. The judge returns structured evidence and can mark a requirement uncertain. Missing or uncertain scores are kept distinct from passes.

This provides a basis for comparing changes to prompts and models. The current dataset is small; broader quality claims require more cases, repeated runs and human review.

Handling persistence and privacy

Request IDs support idempotency, conversation revisions reject conflicting submissions and active-run claims prevent overlapping generations within a conversation. The application checkpoints execution details and recovers expired unfinished runs on a later read or write.

Ordinary results can be shared by link, while private collection conversations are excluded from public access. Optional Braintrust tracking records generation activity and feedback for eligible runs; private runs skip generation tracking.

Tradeoffs and next steps

Execution bounds help keep individual requests manageable, but they are separate from shared user-level cost limits. SVG validation establishes structural safety, while visual quality needs its own evaluation. My next validation priorities are a larger human-reviewed evaluation set, retrieval-specific measurements and latency measurements across representative requests.