Sub topic 15
Measuring whether the policy works
This chapter assumes you have a written AI-assisted code policy that is already rolled out. It assumes you know the pull request workflow, have a CI pipeline, and have worked with a team that reviews code. The goal is to learn whether the policy changes behavior and reduces risk, and to decide what to revise.
Why measure at all
A policy that nobody checks drifts. Rules that seemed clear in the kickoff meeting get bent when a deadline arrives. Rules that are too strict get ignored quietly. Measurement gives you evidence for one of three decisions: keep a rule, tighten it, or relax it.
Measurement here is not surveillance of individuals. The aim is to judge the policy, not to rank people. If engineers think the numbers will be used against them, they will stop disclosing AI use and the data will become worthless. State this plainly when you introduce the metrics.
Start from the policy's goals
Pick metrics that map to what the policy is meant to achieve. A metric with no link to a policy goal is noise.
| Policy goal | Question to ask | Example signal |
|---|---|---|
| Protect data | Is restricted data reaching tools? | Secret-scanner alerts, reported near misses |
| Keep quality | Does AI-assisted code break more often? | Defects traced to changes, reverts, test failures on main |
| Keep review effective | Are reviewers still catching problems? | Review comments per PR, time to first review |
| Keep accountability | Do authors disclose and verify? | Share of PRs with the template completed |
| Keep guardrails working | Do the automated checks fire and get respected? | Required-check bypasses, failed CI rate |
| Keep the policy usable | Do people find the rules workable? | Survey results, exception requests |
Keep the list short. Five or six measures that you review regularly are more useful than twenty that nobody reads.
Leading and lagging signals
Some signals show problems early. Others only show them after damage is done.
- Leading signals show that practices are being followed. Examples are the share of PRs with a completed template and the share of repositories with required checks enabled.
- Lagging signals show outcomes. Examples are production incidents, reverted changes, and leaked credentials.
Use both. Leading signals tell you cheaply whether the rules are followed. Lagging signals tell you whether following them achieved anything. If leading signals are good and lagging signals are bad, the rules themselves are wrong, not the compliance.
Collecting data you already have
You can learn a lot without new tooling. The policy's own artifacts produce data.
- The pull request template. The AI assistance checkboxes record disclosure. Counting how many PRs check each box shows adoption of the tools and of the disclosure habit.
- CI results. The test job runs on every PR regardless of authorship. Failure rates and flaky-test rates show whether quality is holding.
- Branch protection logs. Repository audit logs show whether administrators bypassed required checks or merged without review.
- CODEOWNERS reviews. The time owners take to review changes in sensitive paths shows whether they are a bottleneck.
- Incident and exception records. Each incident report and each exception request is a data point about where the policy hurts or fails.
The next example counts how many merged PRs checked each AI assistance box. It reads the PR body through the GitHub CLI and assumes the template from the earlier chapter.
import json
import subprocess
def merged_prs(limit=200):
out = subprocess.run(
["gh", "pr", "list", "--state", "merged",
"--limit", str(limit), "--json", "number,body"],
check=True, capture_output=True, text=True,
).stdout
return json.loads(out)
def checked(body, label):
for line in (body or "").splitlines():
if label in line and "- [x]" in line.lower():
return True
return False
def main():
prs = merged_prs()
labels = {
"no_ai": "No AI tool was used",
"ai_used": "AI tool used for part of this change",
}
counts = {key: 0 for key in labels}
undeclared = 0
for pr in prs:
found = False
for key, label in labels.items():
if checked(pr["body"], label):
counts[key] += 1
found = True
if not found:
undeclared += 1
print(f"PRs examined: {len(prs)}")
print(f"No AI used: {counts['no_ai']}")
print(f"AI used: {counts['ai_used']}")
print(f"No disclosure answer: {undeclared}")
if __name__ == "__main__":
main()A high "no disclosure answer" count means the template is being skipped or deleted. That is a process problem you can fix with a CI check that fails when the section is empty.
Reading the numbers carefully
Raw numbers mislead in predictable ways.
Disclosure rates are self-reported
The share of PRs that say "AI used" is only as true as the people ticking the box. A low rate might mean low usage or low honesty. Compare it with other evidence, such as a survey that asks how often people use the tools. If the survey says most people use assistants daily and only five percent of PRs disclose it, the disclosure rule is not working. Look for the reason before blaming people. The rule may be unclear about what counts as "part of this change".
Volume changes can be good or bad
If PR count and size go up after adoption, that could mean more output or more churn. Pair volume with a quality signal such as the revert rate. Large PRs also hurt review quality, so track median PR size. A policy that says "keep changes reviewable" should show a stable or falling median size.
Averages hide the tails
An average review time can look fine while sensitive paths wait for days. Report the median and a high percentile, and break results out for the paths covered by CODEOWNERS.
Few events, little statistics
Serious incidents are rare. One leaked secret in a quarter is not a trend. Treat rare events as cases to investigate, not as numbers to chart. Use the incident process to learn from each one.
Beware of targets
When a number becomes a goal, people optimize the number. If you reward a high rate of completed templates, people will tick every box without reading. Use the metrics to start conversations, not to grade teams.
Measuring the guardrails
Automated checks need their own evaluation. A guardrail that blocks too much trains people to route around it. One that blocks too little gives false comfort.
- False positives. Count how often a secret scanner or policy check flags something that was fine. A high rate leads to dismissed alerts.
- Bypasses. Count merges that skipped required checks and why. Frequent bypasses mean the check is wrong or too slow.
- Misses. Review each incident and ask whether a guardrail could have caught it. If yes, and it did not, fix the guardrail.
- Speed. Measure CI duration. Slow checks push people to batch changes into larger PRs.
Asking people
Numbers show what happens. They do not show why. Run a short survey every quarter, with a few questions and anonymous answers.
- Which rules are unclear?
- Which rules slow you down without a clear benefit?
- Have you been unsure whether something was allowed? What was it?
- Do you trust the review process for AI-assisted changes?
Free-text answers about confusing rules often point to the exact wording that needs revision. Exception requests carry the same information. If the same exception keeps being granted, the rule probably needs to change.
Setting up a review cadence
Decide in advance when you will look at the data and who decides.
- Monthly, light. A policy owner checks dashboards or the script output for anything odd. This takes minutes.
- Quarterly, structured. The owner brings metrics, incidents, exceptions, and survey results to engineering leads. The group lists rules to keep, tighten, or relax.
- After any serious incident or major tool change. Review early. New agentic features or a new vendor can invalidate parts of the policy.
Record each decision and its reason in the policy's change log. Next quarter you can then check whether the change had the effect you expected.
Common mistakes
- Measuring only activity. Counting AI usage says nothing about whether the policy reduced risk.
- Using metrics to punish. This kills disclosure and honest reporting.
- Collecting without reviewing. Data nobody discusses has no effect.
- Ignoring qualitative feedback. Surveys and exception requests explain the numbers.
- Never retiring a metric. If a measure no longer informs a decision, drop it.
Exercise
Your quarterly review shows that 40 percent of merged PRs have no answer in the AI assistance section, and a survey shows most engineers use an assistant weekly. List two likely causes and one action for each.
Show answer
Cause 1: The template section is easy to skip or delete, because nothing enforces it. Action: add a CI check that fails the PR when the section has no checked box. Cause 2: The wording is unclear, for example people do not know whether autocomplete counts as "part of this change". Action: revise the policy to define what must be disclosed, with examples, and ask in the next survey whether the rule is clearer. Do not respond by singling out individual authors.
Exercise
Name one leading signal and one lagging signal for the policy goal "restricted data never reaches AI tools", and explain what it means if the leading signal looks good while the lagging signal looks bad.
Show answer
A leading signal is the share of repositories with a secret scanner enabled and the share of engineers who completed data-handling training. A lagging signal is the number of confirmed leaks of secrets or customer data. If the leading signal looks good and the lagging signal looks bad, people are following the practices but the practices do not prevent leaks. The rules or tooling need to change, for example the scanner may miss certain secret formats or the rules may not cover a path through which data escapes.