Policy as Code for Agentic Delivery

Policy as Code for Agentic Delivery

Anthropic's new product, Claude Ship, is a useful signal of where engineering workflows are going: agents are no longer confined to writing a diff. Claude Ship combines code review, PR repair, and an approval-policy agent. The work around the pull request is becoming agentic too.

That extends a point from The Pull Request Is Not the Finish Line. A green PR proves a change passed selected checks. It does not prove the change is safe to release, observable, or reversible.

OpenAI's agentic software factory points the same way: agents work across implementation, review, monitoring, and feedback. Humans stay where judgment and accountability matter.

Datadog's State of AI Engineering 2026 (PDF) frames the 2026-to-2027 shift as an operational one. Its themes, such as gateways, technical debt, framework choices, observability, and prompt caching, are separate experiments I want to run. They are not this post's subject.

First, I wanted to answer a smaller question:

When an agent helps produce a change, how do I make the required checks and human decisions explicit from pull request through release?

So I built a lightweight policy-as-code proof of concept for one of my Next.js web applications.

A deliberately small policy layer

Policy as code can mean a new platform, a policy language, CI enforcement, and a service to operate. I skipped those for time's sake. Life has been busy, and this was a proof of concept first.

The app has a local JSON policy and small Node scripts. They read changed paths, select relevant checks and review prompts, collect evidence, and write a small decision record.

For now it runs in observe mode. It does not approve, merge, tag, publish, deploy, or trigger backups. I want it to mature and earn confidence in my workflow first. Later, I may add scores or ratings that let agents decide whether routine changes can merge automatically.

The rules are simple:

  1. Trust the base: a PR cannot change the policy used to assess itself.
  2. Fail closed: missing or invalid evidence becomes manual review.
  3. Match risk: docs, app, persistence, API, deployment, and policy changes need different evidence.
  4. Keep artifacts secret-free and GitHub writes explicit.

The two flows

Pull request policy

The policy is loaded from the last trusted commit on the base branch, not from the PR branch. A policy change therefore cannot mark itself safe.

Release policy

The evaluator does not deploy. It checks that a smoke plan exists before release; a person records whether it passed after deployment. It checks backup health through an existing status proxy; it never triggers a backup. That keeps a useful control plane from becoming uncontrolled production authority.

What I built

The policy lives in policies/release-governance.json. The scripts live in app/scripts/policy/. Decision artifacts are JSON, written atomically into a git-ignored directory.

Here is an excerpt of the policy. Each rule maps path globs to the checks and human review a change needs:

{
  "version": 1,
  "mode": "observe",
  "default": { "decision": "manual_review_required" },
  "rules": [
    {
      "id": "BF-PAC-002",
      "purpose": "Application changes require the app-focused local quality checks and human review.",
      "paths": ["app/**"],
      "require": {
        "checks": ["unit_tests", "lint", "prisma_validation", "app_production_build"],
        "human_review": true
      },
      "mode": "observe"
    },
    {
      "id": "BF-PAC-003",
      "purpose": "Database migrations and persistence changes add integration, backup, migration, and rollback evidence.",
      "paths": ["app/prisma/**", "app/src/lib/**repository**"],
      "require": {
        "checks": ["integration_tests", "fresh_verified_backup", "pending_migration_review", "rollback_plan_review"],
        "human_review": true
      },
      "mode": "observe"
    },
    {
      "id": "BF-PAC-006",
      "purpose": "Policy and governance changes always require governance review and human review.",
      "paths": ["policies/**", "app/scripts/policy/**", "scripts/preflight-release.sh"],
      "require": {
        "checks": ["governance_review"],
        "human_review": true
      },
      "mode": "observe"
    }
  ]
}

The full file has seven rules. The ones not shown cover docs, CLI, API, and deployment changes. The default decision is manual_review_required, so anything a rule does not cover still goes to a person.

The important interfaces are small. The core is a pure function, and a few helpers around it carry the trust boundary:

// Pure: policy + changed paths + evidence in, decision out. No git, no IO.
export function evaluatePolicy(policy, input) {}
 
// Does a changed path match a rule glob (for example "app/**")?
export function pathMatches(pattern, path) {}
 
// Reads the policy from a trusted git ref, never from the PR branch
function loadPolicy(ref, sourceLabel) {}
 
// Rejects evidence that does not match what the policy requires
function validateEvidenceForPolicy(evidence, policy) {}
 
// Writes the decision JSON through a temp file, then renames it
function writeAtomically(outputPath, artifact) {}

evaluatePolicy does no git or file work, so it is easy to test and the same evaluator serves both flows. The PR and release scripts handle the git and file work around it.

Around them are focused commands that collect PR and release evidence, verify backup health, validate per-version smoke plans, publish an allowlisted PR comment, and attach an allowlisted release artifact.

The biggest usability improvement was automating evidence collection. policy:collect-evidence runs the relevant tests, lint, validation, and build. policy:log-review records a status, reason, timestamp, and append-only review log. A human review is now a first-class event, not a forgotten comment.

It took more than one pass

This was not a quick single iteration. Real PRs and releases exposed issues with pagination, secret-safe output, overly broad rules, smoke-test sign-off, nested human-review status, and integration-test setup. Each fix made the workflow more useful. That is why I would not give an agent approval or deployment authority on day one.

What the reviewer sees

The JSON artifact is for tooling. The PR comment is for the human reader. It lists the trusted policy source, matched rules, required evidence, results, reason codes, and timestamped review log.

Slide 1 of 2

The release artifact follows the same shape: release ref, trusted base, evidence status, human-review status, and audit trail. It is attached to the GitHub release as an asset, so the evidence travels with the version it describes.

Slide 1 of 1

Here is the artifact from that release, trimmed for length:

{
  "kind": "release_policy_decision",
  "mode": "observe",
  "release": { "sourceRef": "v0.0.7", "resolvedCommit": "<sha>" },
  "base": { "sourceRef": "v0.0.6", "resolvedCommit": "<sha>" },
  "trustedPolicy": { "sourceRef": "v0.0.6", "blobSha": "<sha>" },
  "matchedRuleIds": ["BF-PAC-001", "BF-PAC-002", "BF-PAC-006"],
  "requiredChecks": [
    "documentation_validation", "unit_tests", "lint",
    "prisma_validation", "app_production_build", "governance_review"
  ],
  "humanReview": {
    "status": "passed",
    "items": [
      { "id": "release_scope", "status": "passed" },
      { "id": "backup_review", "status": "passed" },
      { "id": "migration_rollback", "status": "not_applicable" },
      { "id": "smoke_scope", "status": "passed" }
    ]
  },
  "decision": "manual_review_required",
  "reasonCodes": [
    "human_review_required",
    "incomplete_or_invalid_evidence",
    "human_review_not_passed"
  ],
  "reviewLog": [
    {
      "check": "release_scope",
      "status": "passed",
      "reason": "approved, human review fix + infrastructure",
      "at": "2026-11-25T20:28:50.693Z"
    },
    {
      "check": "backup_review",
      "status": "passed",
      "reason": "Backup verified via proxy: healthy, 13h ago",
      "at": "2026-11-25T20:28:50.932Z"
    },
    {
      "check": "migration_rollback",
      "status": "not_applicable",
      "reason": "No migrations in v0.0.7",
      "at": "2026-11-25T20:28:51.173Z"
    },
    {
      "check": "smoke_scope",
      "status": "passed",
      "reason": "Smoke plan smoke-v0.0.7.md reviewed",
      "at": "2026-11-25T20:28:51.413Z"
    }
  ]
}

The decision is still manual_review_required. That is the point: the policy does not approve anything, and the reason codes say why a person still has to decide. Every review step is in the log with a status, a reason, and a timestamp.

What I learned

The good

  • Standardized review: the expected evidence is explicit.
  • Checks become evidence: quality signals are captured instead of reconstructed from terminal history.
  • Human judgment is saved: decisions are timestamped and reasoned.

The less good

  • It takes trial and error: policy must match the real app.
  • It is local for now: I did not integrate with CI/CD because this is a proof of concept. That is a possible next step.
  • A passing result is not truth: a human still decides whether the policy covers the real risk.

What comes next

I will use this policy layer across more of my applications. First I want evidence: Which rules catch useful gaps? Which create noise? Which artifacts help during a release?

If it keeps earning its place, I may extract the reusable pieces into an open-source starting point for small teams and solo-maintained apps.

The larger lesson is not “replace reviewers with policies.” It is that agents need deterministic boundaries as they move beyond code generation. They will review, repair, assemble release evidence, inspect dashboards, and propose mitigations.

That can make delivery faster. It can also make mistakes faster and less legible.

Policy as code is one small way to keep the work legible: declare what matters, collect evidence, make human judgment explicit, and improve the rules when reality teaches you something new.

References