How the AI Actually Works

Three agents. Six guardrails. Zero hallucination surface.

The Constraint Philosophy

Most AI tools generate freely, then check what they made. We took the opposite approach.

The design system — tokens, components, patterns — is loaded into the AI's schema before generation starts. The AI cannot reference a color that isn't in the approved palette. It cannot use a component that isn't in the library. It cannot skip a required section like ISI or disclaimers.

This isn't prompt engineering. It's schema engineering. The Zod types that define the AI's output literally cannot represent an unapproved component. Compliance is structural, not aspirational.

Three AI Agents

Brief Interpreter

Converts natural language briefs into structured requirements

Model: Gemini 2.5 Flash (configurable via env var)

Method: generateObject with Zod schema validation — structured output, not free-text parsing

Prompt strategy: Design system context (patterns, markets, components) injected into system prompt — the AI sees ONLY what’s approved

Guardrails

  • Output validated against BriefInterpretationSchema (Zod) — malformed output is rejected
  • pageType must match approved pattern IDs from patterns.json
  • market must match approved market IDs from markets.json
  • mustIncludeComponents restricted to approved component IDs from components.json
  • Risk pre-screening scans for superlatives, missing safety context, off-label indications

Component Selector

Generates two PageSpec variants from structured requirements

Model: Same configurable LLM

Method: generateObject with constrained Zod enum schema

Prompt strategy: Full component props shapes, market-specific requirements, and required disclosures injected

Guardrails

  • componentId is a z.enum() built dynamically from components.json — the AI CANNOT return an unapproved component ID (schema validation fails)
  • tokenId in overrides is a z.enum() built from tokens.json — same constraint
  • Every component must include a selectionReason explaining WHY it was chosen
  • Post-generation: deterministic compliance gate runs 13 rules before rendering
  • Post-processing: adverseEventUrl auto-corrected to market-appropriate regulatory URL

Chat Editor

Applies natural language edits to existing page specs

Model: Same configurable LLM

Method: generateObject with single-variant constrained schema

Prompt strategy: Current page spec + edit instruction, with explicit compliance preservation rules

Guardrails

  • Safety Protocol in system prompt: AI instructed to NEVER remove ISI, Disclaimer, or Footer even if asked
  • Same Zod enum constraints on output
  • Post-edit: compliance gate runs — edits that introduce violations are blocked (HTTP 422)
  • Post-processing: adverseEventUrl auto-corrected

Six Anti-Hallucination Guardrails

  • Structured output only: All three agents use Vercel AI SDK generateObject with Zod schemas. The AI returns validated JSON, not free text. If output doesn’t match the schema, the request fails and retries (max 2 retries).
  • Enum-constrained generation: Component IDs and token IDs are Zod enums built at runtime from the design system JSON files. The LLM literally cannot hallucinate a component that doesn’t exist — schema validation rejects it.
  • No LLM in compliance decisions: The compliance gate is pure TypeScript functions. Pass/fail is deterministic, not AI judgment. The AI generates; pure functions validate.
  • Post-processing layer: Even after Zod validation, deterministic post-processing fixes known LLM weaknesses (e.g., adverseEventUrl often outputs "#" despite prompt instructions — auto-corrected per market).
  • Risk pre-screening: Brief interpreter flags potential compliance risks BEFORE generation starts, not after.
  • Dual-layer adversarial protection: (1) Prompt-level Safety Protocol tells the AI to preserve safety components. (2) Deterministic compliance gate catches anything the prompt misses.

What the AI Cannot Do

This is critical for trust:

  • AI does NOT decide compliance pass/fail — pure functions do
  • AI does NOT have access to the internet during generation — all context is injected from local JSON files
  • AI does NOT store or learn from previous generations — each request is stateless
  • AI does NOT generate raw HTML — it generates a PageSpec (JSON), which is rendered by deterministic React components
  • AI output is NEVER rendered without passing through the compliance gate first

Cost Efficiency

  • Default model: Gemini 2.5 Flash (Google) — free tier for development, low-cost for production
  • Multi-provider architecture: Switch between Google, Anthropic, or OpenRouter via env var — no code changes
  • Single LLM call per pipeline step: interpret (1 call), generate (1 call), edit (1 call) — no chains or loops
  • Structured output eliminates parsing costs: no regex, no retries for format issues
  • Chat edits use single-variant schema (halved output tokens vs original two-variant approach)

The Proof: Audit Trail

  • Every pipeline step logged with SHA-256 hash chain
  • Each entry includes: timestamp, action, actor, input hash, output hash, chain hash
  • Chain integrity verifiable at /evidence — re-computes all hashes live
  • Follows FDA 21 CFR Part 11 principles for electronic records

See the live audit chain at /evidence.