How to make your design system hard for AI to misuse
Coding agents don’t ignore your design system on purpose. They guess from memory, and nothing tells them they guessed wrong. These eight steps are the method we use in Kata Setup, in the order we apply it, with what each one changed in our own tests.
The short version
- Docs tell the agent what’s right. Types, rules and Storybook reduce mistakes.
- Checks tell it when it’s wrong. Docs alone left some screens failing in our tests; a type check removed the rest, every time we ran it.
- Measure before and after. Otherwise you can’t tell which step helped.
1. Measure before you change anything
Pick 10 everyday screens your team actually builds: a form, a table, a dialog, a settings page, an empty state. Give each one to your coding agent with only your design-system package installed, then compile every file against the version you ship with
npx tsc --noEmit.Count four things: screens that compile, how much of the UI is your components rather than raw HTML, values typed by hand instead of tokens, and components the agent rebuilt instead of reusing. That baseline tells you which of the next steps you need, and proves later whether they worked.
2. Make your types tell the truth
Agents read types more reliably than docs. Remove deleted APIs from the types instead of leaving them half-working, mark deprecated ones with
@deprecated, export the prop types of every component, and prefer closed unions (variant: 'primary' | 'secondary') over open strings.In our tests a well-typed design system scored 99 out of 100 with no help at all. Our own system went from 95 to 100 once we added the layout and heading components agents kept reaching for, and exported the types they needed.
3. Give every value a token, then lint for raw ones
Semantic tokens (
--color-text-muted,--space-4) give the agent a name to use instead of a number to invent. Then add a lint rule that flags hex colors and pixel values in product code, so the next one fails in CI instead of slipping through review.This is where screens go “almost right”. In our Carbon test the agent used Carbon’s components, then added 41 hand-typed margins, sizes and colors on top. Every screen worked. With rules, it wrote none.
4. Write short rules for your agent
One short file the agent always reads (
AGENTS.md,CLAUDE.mdor.cursor/rules): which components exist, where to import them from, which layout primitives to use, tokens only, and to check its work before handing over. Keep it short enough that a person would read it too.# Design system rules - Build UI only from @acme/ui. Never raw <button>, <input> or styled divs. - Import experimental components from '@acme/ui/experimental'. - Layout goes through <Stack>; headings through <Heading>. - Colors, spacing and sizes come from tokens (var(--acme-*)). No hex, no px. - Before you hand over, run `npx tsc --noEmit` and fix every error.Spell out subpath entry points such as
experimentalornext: that’s where agents guess wrong most. With no rules, 8 of 10 screens our agent wrote for GitHub’s Primer didn’t compile, because it remembered components Primer had removed. With rules, none failed.5. Make Storybook the contract
One story per component with usage docs, and full screens as stories too, so the agent can copy how your team composes a page instead of improvising. Then turn on the Storybook MCP (
@storybook/addon-mcp), so the agent reads your real props and examples before it writes.Then read what your docs actually say. With Primer’s official Storybook MCP, failing screens dropped from 9 to 4 out of 10, but the docs gave root imports for components Primer only exports from
@primer/react/experimental, and the agent followed them. The full test.6. Let the agent check its own work
This is the step that turns fewer errors into none, reliably. Allow the agent to run the type check, and Storybook’s
test-runtool if you use the Vitest addon. Then run the same checks in CI on every pull request, for code written by people and by AI.In our tests on Elastic’s EUI, rules plus a documentation MCP reduced failing screens but never removed them. Adding a type check took them to zero in three rounds out of three. With Primer, the agent read the compiler error, fixed the import and tried again, in 6 of 10 tasks.
7. Connect Figma, if you build from frames
When the agent turns a Figma frame into code through Figma’s MCP, it only uses your components if Figma knows which code component each layer is. Map your library with Code Connect, and keep your tokens in sync with Figma variables, so a frame arrives as your components and tokens rather than lookalike divs with hand-typed styles.
Code Connect needs a Figma Organization or Enterprise plan. We haven’t measured this step yet, so we don’t quote a number for it.
8. Measure again, then keep measuring
Run the same 10 tasks again. The difference is your proof, and the remaining failures are your next list. Repeat whenever your design system ships a major version or your team changes agent or model: the same agent can do well on one release and fall back on the next.
Checklist
- A baseline: 10 tasks, compiled against the version you ship
- No removed APIs left in the types; deprecated ones marked
- Prop types exported; variants as closed unions
- Semantic tokens, and a lint rule for raw colors and sizes
- A short rules file, with every subpath entry point named
- A story per component, plus full screen patterns
- Storybook MCP on, and its imports checked against your exports
- The agent allowed to type-check; the same checks on every pull request
- Code Connect and synced variables, if you build from Figma
- The same test again, after every major release
Where the numbers come from
Every figure above comes from tests published on this site: 10 everyday UI tasks per condition, one agent, every file compiled against the exact package version. They are small samples and show trends, not guarantees. Read the research for methods and limits.
Want step 1 done for you?
We run the same 10 tasks on your package and send a two-page report in two business days. Free.
Get a free score