Constraining LLM Output to a Design System Contract
A V0 demo for a YouTube series exploring how to constrain AI-generated UI code to use only allowed components, props, and design tokens — moving beyond prompt engineering toward enforceable structure.
LLMs are good at generating UI code, but poor at respecting long-lived constraints like design systems, component contracts, and tokens.
This project explores a simple but powerful idea:
If you define constraints as data and validate against them, AI output becomes governable — not just impressive.
This project demonstrates a pattern for ensuring AI-generated JSX adheres to a predefined design system:
-
Single Source of Truth
A design system contract that can be used for:- AI prompting
- Output validation
- (Future) type generation
-
Deterministic Components
UI components that use design tokens only, not arbitrary values. -
Validation Layer
Programmatic verification that generated UI code complies with the contract.
tokens.ts— Design tokens (colors, spacing, radius, typography)contracts.ts— Component and prop definitions that constrain what AI can outputindex.ts— Barrel exports for clean imports
All components use token keys for styling. V0 intentionally keeps the surface area small:
-
Button.tsx- Variants:
primary,danger - Sizes:
sm,md
- Variants:
-
Card.tsx- Container component with configurable padding
-
TextInput.tsx- Labeled form input with optional
requiredstate
- Labeled form input with optional
validate.tsvalidateOutput(tsx: string) → { ok, violations }- Validates:
- Allowed components (
Button,Card,TextInput) - Allowed props per component
- Basic structural correctness (V0 uses string/regex checks)
- Allowed components (
npm install
npm run dev
## Status
This is a V0 foundation. Validation and AI integration are intentionally not implemented yet.