Guardrails in CI: speed you can merge with confidence
The design principle for AI code guardrails in CI fits in one sentence: the pipeline does not care who wrote the code. Not a separate lane for AI-generated changes, not an honor-system checkbox asking whether Copilot was involved. One set of gates, enforced on every merge, strict enough that code passing them is safe to ship whether it came from your most careful senior or an agent running overnight.
Teams ask for the AI-specific version of this and the honest answer is that there barely is one. What changes with agents is volume and the failure distribution: more code, arriving faster, with mistakes that are confidently wrong rather than obviously sloppy. Quality controls that lived in habits and hallway culture (we always add tests, we never touch that module without telling Sarah) do not survive that volume. The fix is moving them somewhere they cannot be skipped on a busy Friday, and that place is CI.
Guardrails that belong in CI
Tests, enforced, not encouraged. Changed code requires passing tests, and coverage on changed lines is the gate we use rather than global coverage, which punishes people for the sins of the past. Agents are conveniently good at writing tests, so the objection that this slows everyone down has aged badly. The deeper pattern, using the test suite as the leash that makes delegation safe, deserves its own note, but the CI half is simple: no green, no merge.
Static analysis at maximum severity. Linters, type checkers and complexity limits, with warnings promoted to errors on changed files. Agents follow the conventions they can see enforced; a warning that has been ignored for three years teaches them, and everyone else, that the rule is decorative.
Security scanning on every PR: SAST on changed code, secret detection, and dependency checks, because agents add packages readily and a hallucinated or typosquatted dependency is now a real attack path. Given how often AI-generated code carries a vulnerability, running these post-merge or quarterly is a policy from a slower era.
Conventions as code. Architectural rules (this layer does not import that one), naming, API patterns: everything you can express as a lint rule should be one, because a rule in CI is context an agent reliably respects, while a rule in a wiki is a suggestion nobody reads.
Rules the pipeline enforces about people
CI is also where review policy stops being aspirational: branch protection, required reviewers on sensitive paths (auth, payments, data deletion, infrastructure), no self-merge, and CODEOWNERS actually maintained. Under AI volume, review is exactly where delivery breaks first, and the temptation to soften the rules to clear the queue is strongest precisely when it is most dangerous. Encode the rules where softening them requires a visible, deliberate act.
One addition earns its place in the AI era: diff size limits, hard or advisory. Agents happily produce eight-hundred-line PRs, and no human reviews eight hundred lines, they skim them. Forcing work into smaller merges is the single cheapest improvement to review quality we know.
What CI cannot catch
A pipeline verifies properties, not intent. It will not notice that the change solves the wrong problem, quietly weakens a domain invariant, or duplicates a service that already exists two directories away. That last failure is measurably growing: duplication and dead weight are the signature of AI-assisted technical debt, and no gate catches what is syntactically fine and architecturally wrong.
So the guardrails buy you something specific: they make the mechanical failures impossible, which frees human review to do the only work it is uniquely good at, judging intent and design. Teams that get this division right stop asking reviewers to be linters, and stop expecting linters to be architects.
Start with the ratchet
Retrofitting all of this onto a living codebase sounds like a quarter of work. It is not, if you ratchet: every gate applies to changed code only, starting now. New and touched files meet the bar; the legacy backlog gets cleaned opportunistically, often by agents, module by module. In our experience a team gets the core set (test gates, promoted lint, secret and dependency scanning, protected paths, a diff budget) running inside two weeks, and the arguments about whether AI code is trustworthy mostly evaporate, because trust stops being the mechanism. When something still gets through, as it eventually will, the postmortem pattern for AI-written code turns the incident into a better gate.
Building this ratchet, sized to the team’s stack and risk profile, is one of the first concrete deliverables of our agentic engineering engagements: guardrails first, then volume, in that order.