Sub topic 3
Enforcing an AI-Assisted Code Policy
Assume you know basic Git, pull requests, code review, and CI pipelines. The goal is to make policy rules happen automatically where possible.
Enforce checks with CI and branch protection
Run the same tests for every pull request, whether a person or an AI tool wrote the code. Mark the CI job as a required status check in branch protection. Require approval from the correct reviewers, and prevent merging when checks fail.
# .github/workflows/ci.yml
name: ci
on:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm testUse repository ownership rules for sensitive paths. A change under /payments/ might require approval from the payments team. A common error is running CI but leaving it optional.
Limit agentic permissions
An agentic tool can run commands or edit files. Give it the smallest useful scope:
- Use a temporary branch or workspace.
- Allow read access by default.
- Require approval before network access, deployments, migrations, or destructive commands.
- Keep secrets out of prompts and agent environments.
- Separate development credentials from production credentials.
Roll out and revise the policy
Start with a short policy defining allowed, restricted, and prohibited uses. Name the policy owner and an exception approver. Pilot it with one team, collect questions, then publish examples. Review it after incidents, tool changes, or major repository changes.
Train and onboard
Add the policy to onboarding. Show developers how to check generated code, remove sensitive data, disclose assistance, and request an exception. A pull request template can remind authors to read and test every line.
> callout note > Automation enforces repeatable rules. Human review remains responsible for intent, security, and correctness.
Handle incidents and measure results
Define an incident path for leaked data, insecure generated code, license concerns, or policy bypasses. Contain the change, notify the appropriate security or legal owner, preserve evidence, and update the policy.
Track useful signals such as failed required checks, security findings, policy exceptions, review delays, and incidents involving AI-assisted changes. Review trends with engineers instead of rewarding teams for merely reporting fewer incidents.
Exercise
Why should CI be a required branch-protection check?
Show answer
Otherwise a pull request can bypass the team's testing rule and merge without passing the same checks as other changes.