Mesrai
Back to blog
// essayBest Practices

Can an AI Reviewer Learn Your Team's Unwritten Rules?

Conventions that live only in people's heads become review labour. A three-PR experiment for deciding whether a custom AI review rule is trustworthy enough to turn on.

Arjun MehtaNovember 20, 20269 min read

Every team has rules that live only in people's heads: "use our retry wrapper for background jobs," "never call the billing API directly from a controller." They are real, they matter, and today they are enforced by whichever senior engineer happens to review the PR. The promise of a custom AI review rule is to move that knowledge out of heads and into something that runs on every pull request. The risk is that you teach the rule badly and it either misses the violations or flags things it shouldn't. This is a three-PR experiment for deciding whether a given rule is trustworthy enough to turn on.

Why does the same review comment appear every sprint?

Watch a team's review history and you will see the same comment, sprint after sprint: "Please use the `withRetry` wrapper for this background job." A convention that exists only as tribal knowledge becomes recurring review labour — one reviewer spends attention re-explaining it, authors keep rediscovering it, and new joiners trip on it for months. The comment repeating is the signal. It means a rule exists, it is worth enforcing, and right now a human is the enforcement mechanism. That is exactly the kind of rule worth teaching a reviewer — and exactly the kind that is easy to teach wrong.

Which conventions are worth teaching a reviewer?

Not every preference deserves a rule. Rank candidates on four axes: frequency (how often it comes up), cost of a mistake (what breaks when it's violated), clarity (can you state it unambiguously), and ease of verification (can a reviewer check it from the diff). A recurring operational requirement — "background jobs must go through the retry wrapper or they silently drop work" — scores high on all four and is a strong first experiment. A stylistic preference — "we like early returns" — scores low on cost and is a poor one. Start where frequency and cost are both high and the rule is checkable.

What is the actual rule behind the review comment?

"Use our wrapper" is not a rule; it is a shorthand for one. Translate it into the behaviour it protects: background jobs must run through `withRetry`, which guarantees consistent retry handling and prevents duplicate execution. Now the rule names a trigger (a background job), a mechanism (`withRetry`), and a reason (retries + idempotency). A reviewer — human or AI — can evaluate a change against that. "Follow our conventions" cannot be evaluated against anything.

Where should the rule apply?

Scope is half of a good rule. Specify where it holds — which directories, which job types, which execution paths — and, just as importantly, name a place where it is irrelevant. "Applies to handlers in `jobs/`; does not apply to synchronous request handlers in `api/`." Without an explicit scope, a rule either under-fires (too narrow, misses real cases) or over-fires (too broad, flags unrelated code). Naming the irrelevant zone is what stops the rule from becoming noise the moment someone writes a normal function that happens to look like a job.

A rule card with trigger, must, why, exception and scope, beside the three-PR test: PR1 clear violation should flag, PR2 approved exception should stay quiet, PR3 unrelated change should stay quiet
A trustworthy rule flags the violation and stays quiet on the exception and the unrelated change.

What is a legitimate exception?

Every real rule has exceptions, and a rule that cannot express them is a rule that cries wolf. Define one concretely: a one-off administrative job, run manually, with an explicitly approved execution pattern, may bypass the wrapper. Then state what makes the exception recognizable — a marker, an annotation, a directory. If the reviewer cannot tell an approved exception from a violation, it will flag the exception every time, the team will learn to ignore the rule, and you are back to tribal knowledge plus an annoying bot.

How to write a version a reviewer can evaluate

Give the rule four parts: trigger (what code it applies to), expected behaviour (what that code must do), exception (when it doesn't), and example (one violation, one compliant). Compare that with "follow our internal standards," which hands the reviewer no trigger, no test, and no boundary. The specific version produces specific, checkable comments. The vague version produces confident guesses, because you have asked the reviewer to infer your conventions instead of stating them.

When should a convention become a lint rule instead?

Before you reach for contextual AI review, ask whether a deterministic check can do it. If the rule is "don't import `billingClient` outside `services/billing/`," an import-restriction lint rule enforces that perfectly, every time, with zero false positives and no model cost. Reserve AI review for rules that genuinely require interpretation — "this job isn't idempotent and should be" — which no static rule can express. Deterministic first, contextual only when interpretation is unavoidable, is the cheapest way to enforce a convention reliably.

What is the difference between a rule and a remembered preference?

There is a real distinction worth being deliberate about. A rule is an explicit policy you write down, scope, and version — the team has decided it, and it applies consistently. A remembered preference is softer context a reviewer carries — "this team tends to prefer X" — which is useful but not a hard check. Tools like Mesrai separate the two for a reason: a policy you want enforced on every PR should be an explicit, owned rule, not an accumulated habit the system inferred and might apply unpredictably. Decide which one you are creating before you turn it on.

Test PR one: the clear violation

Write a PR that plainly breaks the rule — a background job that bypasses `withRetry` — and run the reviewer. Record three things: did it identify the correct line, did it explain the consequence (dropped work on retry), and did it recommend the established fix? Catching the violation is necessary but, on its own, not sufficient. A rule that only ever fires is easy; the next two PRs are where you find out whether it fires well.

Test PR two: the approved exception

Introduce the same mechanism in a legitimately exempt context — the one-off admin job with its approval marker. Now the question flips: does the reviewer recognize the exception and stay quiet, or does it flag it anyway and manufacture review work? This is the PR that most rules fail. A rule that cannot distinguish a violation from an approved exception will, in production, nag your team on every legitimate edge case until they mute it — taking its real catches down with it.

Test PR three: the unrelated change

Modify code that has nothing to do with the rule — a change in a completely different area that happens to share a keyword or a shape. Record whether the rule stays silent. A rule whose wording accidentally matches unrelated patterns is a false-positive generator waiting to scale across your whole codebase. If PR three produces a comment, the rule is matching on surface features, not on the behaviour it was meant to protect, and it is not ready.

How to interpret all three results together

Read the three PRs as one result, not three. Catching the violation (PR one) alone tells you almost nothing. A trustworthy rule does all three: flags the real violation, and recognizes the approved exception, and stays quiet on the unrelated change. A rule that catches PR one but also flags PRs two and three is too expensive to enable broadly — its true catches come bundled with a stream of false ones, and the team's trust erodes faster than the rule helps.

How to revise a rule without teaching to the test

When a rule fails PR two or three, improve the instruction — tighten the scope, sharpen the exception marker — and then test it on fresh variants in different files, not the same three fixtures. Keep the original three as regression checks, but never tune until they pass and declare victory, because a rule overfit to three examples will break on the fourth. The goal is a rule that generalizes to code you have not seen, which is the only code it will ever actually review.

Who owns rules when architecture changes?

A rule is a living artifact with an owner. Assign each one a maintainer, a source document explaining why it exists, and a review trigger. Then plan for change: when the internal library the rule enforces is replaced or its responsibilities move, the rule has to move with it, or it becomes a reviewer enforcing a convention the team abandoned six months ago. An un-owned rule does not stay correct; it quietly rots into noise, and noise is where trust in the whole system goes to die.

The custom-rule specification template

Close with a template to fill in for every rule you add: purpose, scope, expected behaviour, exceptions, owner, positive example, negative example, and last verified revision. If you can fill all eight, you have a rule a reviewer can evaluate and a team can trust. If you cannot, you have a preference — keep it in code review as a human comment until it is sharp enough to write down. That boundary, more than any model, is what decides whether a custom rule helps or just adds to the noise.

Frequently asked questions

Can an AI code reviewer learn a team's unwritten rules? It can enforce rules you make explicit — with a trigger, expected behaviour, scope, and exception — far better than it can infer them. Vague instructions like "follow our conventions" produce guesses; a written, scoped rule produces checkable comments.

How do you test a custom AI review rule before enabling it? Run three PRs: a clear violation (should flag), an approved exception (should stay quiet), and an unrelated change (should stay quiet). Only a rule that passes all three is safe to enable broadly.

When should a convention be a lint rule instead of an AI rule? Whenever a deterministic check can enforce it — import restrictions, naming, formatting. Reserve AI review for rules that genuinely need interpretation, which static analysis cannot express.

// try

See it on your next PR.

Free for individual developers as a launch offer. Set up in about 2 minutes. Mesrai reviews every commit.