Guides · September 26, 2023
Using a Starter as Your AI Guardrails: Generate Inside the Lines
AI code guardrails work best when they are structural, not just written: a well-built starter constrains an AI coding agent to your patterns before it ever writes a line, instead of correcting it after the fact.
By Polo Themes
The most reliable AI code guardrails are not prompts or review checklists — they are the starter codebase itself. When an AI agent generates a new component, it copies whatever patterns already exist in the repo: your folder structure, your naming conventions, your state-management choices, your accessibility habits. A starter with strong, consistent conventions gives the agent a narrow, well-marked lane to generate inside. A messy or inconsistent starter gives it a hundred conflicting examples to imitate, and it will imitate the bad ones just as eagerly as the good ones.
This matters more now than it did two years ago, because the balance of who writes the first draft of a component has shifted. A large share of new code in AI-assisted teams is now agent-authored, with a human reviewing rather than typing. That shift makes the starting conditions of a codebase — its structure, its constraints, its examples — a bigger lever on code quality than any individual prompt, because the agent is pattern-matching against your codebase far more than it is reasoning from your instructions.
Why Prompts Alone Are Weak Guardrails
The instinct when an AI agent produces code that does not match your standards is to write a longer, more detailed prompt: "always use our Button component," "never inline styles," "follow our error-handling pattern." This works for a turn or two, then degrades. Prompts are advisory. They compete with everything else in the context window — the rest of the conversation, other files the agent has read, and its own training-time defaults, which lean toward generic patterns that show up most often across the open web. A single instruction buried in a long system prompt is easy for a model to under-weight, especially several turns into a session.
Structural constraints do not compete for attention this way, because the agent does not have to remember them — it observes them directly in the code it is extending. If every existing form in the repo validates with the same library, calls the same submit helper, and renders the same error component, an agent extending that repo will very likely do the same, not because it was told to but because that is the path of least resistance: copying a working, adjacent example is almost always easier than inventing a new pattern from scratch. Guardrails that live in the codebase survive context loss, model switches, and long sessions in a way that guardrails that live only in a prompt do not.
What a Guardrail-Grade Starter Actually Contains
Not every starter constrains an AI agent equally well. A starter optimized for guardrails has a specific set of properties, most of which are also just good engineering practice — AI-readiness and code quality converge here rather than trade off against each other.
One way to do each thing, not three
If a starter has two different data-fetching patterns left over from a half-finished migration, an AI agent will pick up both, sometimes in the same file. Before layering agentic tooling onto a codebase, it is worth consolidating: one fetching pattern, one form pattern, one modal pattern, one way to define a page layout. This pruning work has a real cost up front, but it pays back every time an agent generates something new, because there is only one precedent to copy.
Conventions expressed as code, not just documentation
A style guide describing "how we structure a component" is useful for a human onboarding, but an AI agent will trust an existing component in the folder it is working in more than a paragraph in a docs page it may not even read. The most durable version of a convention is a real, working example sitting exactly where a new file would be created — a template component, a reference hook, a canonical API route — that the agent can literally open and pattern-match against.
A component boundary the agent cannot easily route around
Guardrails hold better when they are enforced by the type system and the build, not just by convention. A shared design-token layer that primitives must consume, a component library with a small, well-typed public API, and lint rules that fail the build on raw hex values or ad hoc spacing all make it structurally harder for generated code to drift, even under time pressure. This is one reason design assets built with strict, semantic tokens rather than freeform CSS values act as guardrails almost automatically — there is no direct value to fall back to that bypasses the system, so both a human and an agent are pushed toward composing existing tokens and components rather than inventing new ones.
Fast, deterministic feedback loops
Type errors, lint failures, and a fast test suite are guardrails an agent can actually see and self-correct against inside a single working turn. A starter with strict TypeScript, a comprehensive lint config, and a quick test command gives an agent (and a human reviewer) a tight loop: generate, run the checks, fix, repeat — all before a human even opens the diff. A starter without these checks pushes all of that correction downstream into code review, where it is slower, more expensive, and easier to skip under deadline pressure.
Accessible and responsive patterns baked into the primitives
Accessibility is a category where AI-generated code is disproportionately likely to regress, because correct ARIA usage, focus management, and keyboard interaction are easy to get subtly wrong and hard to catch by eye. If the starter's base primitives — buttons, dialogs, menus, form fields — already handle focus trapping, labeling, and keyboard navigation correctly, an agent that composes those primitives inherits the correct behavior automatically. An agent asked to build a dialog from raw HTML elements has to get accessibility right from scratch every single time, and it will not always succeed.
A Practical Checklist Before You Turn an Agent Loose
Before pointing an AI coding agent at a codebase for anything beyond a small isolated fix, it is worth running the repo through a short readiness check. Each item below is something you can verify in minutes, and each one directly reduces the surface area for the agent to improvise on.
- Audit for duplicate patterns. Search the repo for more than one way to fetch data, validate a form, or fire a toast notification. Consolidate to one before adding agent-driven changes on top.
- Confirm a canonical example exists for every common shape. A page, a form, a data table, a modal — each should have one reference implementation an agent can be pointed at or will naturally discover nearby.
- Turn on strict type-checking and comprehensive linting, including rules that catch raw color values, inconsistent spacing, and missing accessibility attributes, so the build itself rejects drift.
- Write a short, current contributor guide (many teams now keep this as an AGENTS.md or CLAUDE.md alongside the README) that names the canonical patterns and points to their file locations, so an agent reading it before generating code has a map, not just a wall of prose.
- Add a fast pre-commit or CI check for the highest-value guardrails — type errors, lint failures, broken tests — so violations are caught in seconds rather than surfacing days later in review.
- Review the first several agent-generated pull requests closely, specifically looking for pattern drift rather than only functional correctness, and feed anything that slips through back into the starter as a new canonical example or lint rule.
Design Assets as an Early Guardrail Layer
Guardrails do not have to wait for a codebase to exist — they can start at the design stage. A Figma kit built on a strict, named token system (spacing scale, type scale, a fixed color palette, consistent component variants) hands an AI-assisted build process a much narrower set of legitimate choices than a freeform mockup does, whether the handoff is manual or through an AI design-to-code tool. When the design source is already disciplined, less improvisation is available to the coding agent downstream, because there are fewer values it could plausibly invent that are not already defined. This is part of why we build our own Figma UI kits around consistent, named component and token systems rather than one-off screens — it is good design practice on its own, and it happens to make whatever gets built from that design harder to get subtly wrong.
Where This Is Heading
The natural extension of this idea is a starter that documents its own conventions in a form an agent can consume directly and act on with minimal reinterpretation — canonical examples, explicit constraints, and a clear map of "generate here, not there" that an agent reads before it writes a single line, rather than conventions that live only in a human's head or a Slack thread. That is the direction commerce tooling is heading generally, and it is the direction we are building toward as we expand beyond Figma kits and Shopify themes. For now, the highest-leverage move available to any team adopting AI coding agents is the one described above: audit the codebase for duplicate patterns, consolidate to a single canonical example per shape, turn on strict type and lint checks, and write down the conventions where an agent will actually look. Do that work once, and every AI-generated pull request afterward starts from a narrower, better-marked lane.
Frequently Asked Questions
Do AI coding guardrails replace code review?
No. Guardrails reduce how often review needs to catch pattern drift or structural mistakes, freeing reviewers to focus on business logic, edge cases, and architecture decisions instead of re-explaining conventions on every pull request.
Can I add these guardrails to an existing, messy codebase, or do I need to start over?
You can add them incrementally. Start by consolidating the most-duplicated patterns (data fetching, forms, and any component with several near-identical implementations), then layer in stricter lint rules and a short conventions document. A full rewrite is rarely necessary; consistent examples in the areas an agent touches most often deliver most of the benefit.
Does a stricter design system slow designers down?
It changes where the effort goes rather than removing it. Early decisions about tokens and component variants take deliberate thought, but every screen built after that point is faster to design and faster to build correctly, because both the designer and any AI tooling downstream are composing from a fixed, well-understood set of pieces instead of inventing new values each time.
Is Polo Themes building AI-native starter templates?
Not yet — today we build Figma UI kits and Shopify themes, both designed around strict, consistent token and component systems. Structured, agent-friendly starters and component registries are a direction we are actively exploring as commerce tooling moves toward AI-assisted builds, and it is a natural extension of the same disciplined-system approach we already apply to our Figma kits.