---
title: "How to Apply Policy as Code in Data Governance"
url: "https://atlan.com/know/ai-agent/ai-agent-governance/policy-as-code-data-governance/"
description: "Learn how policy as code works in data governance: seven steps from a written policy to an enforced, logged rule, with tests, a dry run and an owner."
author: "Emily Winks"
author_role: "Data Governance Expert"
published: "2026-11-20"
updated: "2026-11-20"
---

## What is policy as code in data governance?

Policy as code in data governance means writing a rule once in a declarative language, keeping it in version control, testing it like software and letting a system enforce it. Atlan's AI Context Platform holds the business policy in Policy Center, the access rules in personas and purposes, and data contracts in Git, so each rule keeps an owner and a trail. Seven steps take you from the written policy to an enforced, logged rule.

On this page:

- **What policy as code is**, and why AI agents make it urgent
- **Which policies to write first**, and what stays human
- **Seven steps** from written policy to logged decision
- **What goes wrong**, and how Atlan supports it

## Key takeaways

- Policy as code is a governance rule written once, versioned, tested and enforced by software.
- Keep a link from every rule to a written business statement with a named owner.
- Run a new rule in audit mode before it blocks anything, and log every decision.
- Judgment, exceptions and the purpose of a policy stay with people.

---

Apply policy as code in seven steps and turn a written data policy into a tested, enforced and logged rule that keeps a business owner. Policy as code means writing a governance rule as versioned code, testing it like software and letting a system enforce it. Atlan's AI Context Platform holds the business policy and its owners in Policy Center, the access rules in personas and purposes, and data contracts you manage from Git, while the engine you choose evaluates the rule.

Gartner uses the term "policy as code" for continuous and runtime enforcement in its latest edition of the [Magic Quadrant for Data and Analytics Governance Platforms](https://atlan.com/know/gartner/magic-quadrant-for-data-governance-november-2026/), and you can [download the free report from Atlan](https://atlan.com/gartner-magic-quadrant-data-governance-2026/). If you lead data governance, your rules probably sit in documents while AI agents and a growing list of systems query the same data, so nobody can show an auditor which rule ran or whether it ever blocked anything. The link back from the rule to the business owner who asked for it is the easiest step to lose, so the seven steps below keep the two joined. Four questions run through them:

- Who approves the policy, and who can read the rule that implements it?
- How is the rule tested before it touches real requests?
- How is it rolled out without blocking people by surprise?
- How is every decision logged for the audit that will ask?

### Check where a governance control runs

Takes one governance decision or control and returns pass, partial or fail per surface (ticket, pull request, pipeline, BI tool, SQL editor, team chat, agent tool call) with the first two fixes. [Read the skill](/skills/governance-workflow-embed-check.md).

*Paste into a new chat*

```
Use the skill at https://atlan.com/skills/governance-workflow-embed-check.md to check where one governance control runs across surfaces. Ask me for whatever it needs.
```

*Run once in a terminal*

```
curl -fsSL --create-dirs \
  -o ~/.agents/skills/governance-workflow-embed-check/SKILL.md \
  https://atlan.com/skills/governance-workflow-embed-check.md
```

*For an agent*

```
curl -fsSL https://atlan.com/skills/governance-workflow-embed-check.md
```


    Human
    Agent


  ClaudeChatGPTGeminiCursorOther
  Copy

| Quick facts | |
|---|---|
| What it is | A governance rule written as code, versioned, tested and enforced by software |
| Written in | Code, often a declarative language, or a structured file such as a YAML data contract |
| Lives in | Version control, linked to a written business policy with a named owner |
| Checked by | Automated tests, then an audit-mode run, then enforcement with a decision log |

---

## What is policy as code in data governance?

Policy as code is a governance rule written as code, often in a declarative language, stored in version control and evaluated by software instead of read by a person. The engine separates the decision from the enforcement: the [Open Policy Agent documentation](https://www.openpolicyagent.org/docs) says OPA "decouples policy decision-making from policy enforcement," and the [Cedar language reference](https://docs.cedarpolicy.com/) says its policies are "completely separate from your application's code."

What makes it data governance is what the rule is about. The rule talks about a column, a table, a tag or a purpose, not a server. A [data governance taxonomy](https://atlan.com/know/ai-agent/ai-agent-governance/data-governance-taxonomy/) supplies the categories the rule refers to, and the [data governance operating model](https://atlan.com/know/ai-agent/data-governance-operating-model/) says who owns the decision behind it.

It is also worth saying what it is not. It is not the business policy itself, and it does not replace the owner who wrote that policy. For a fuller view of the written side, see [what a policy bench is](https://atlan.com/know/ai-agent/ai-agent-governance/what-is-a-policy-bench/) and the [AI governance framework](https://atlan.com/know/ai-readiness/ai-governance-framework/) that sits around it.

---

## Why apply policy as code to data governance now?

More systems and more AI agents now touch the same data, and a rule kept only in a document gives none of them anything to check. Three pressures show up together.

Rules live in many enforcement points: warehouses, pipelines, BI tools and agent tool calls each need the same rule applied the same way. [Policy enforcement across operational, analytical and AI data](https://atlan.com/know/ai-agent/ai-agent-governance/policy-enforcement-operational-analytical-ai/) covers where each of those fires, and the broader pattern is in [data governance policy enforcement](https://atlan.com/know/data-governance/policy-enforcement/).

Agents also act on data under a person's or service account's identity, so they need a rule that software can evaluate on every call, including who the agent is acting for and what purpose the call serves. That is the core of [AI agent access control](https://atlan.com/know/ai-agent-access-control/) and [AI agent identity](https://atlan.com/know/ai-agent/ai-agent-identity/). Two research papers on arXiv point the same way: [Policy-as-Prompt](https://arxiv.org/abs/2509.23994) turns governance documents into a source-linked policy tree and runtime guardrails for agents, and [Progent](https://arxiv.org/abs/2504.11703) represents privilege as "a security policy consisting of symbolic rules over tool names and arguments." Progent is a preprint, and Policy-as-Prompt relies on a model to interpret the rule, so read them as a contrast with the deterministic approach described here, not as a template for it.

Finally, audits ask which rule ran, on what, and when. A document cannot answer that. A decision log can. 

The cost of leaving this unsolved is the story in [AI exposes data governance debt](https://atlan.com/know/ai-agent/data-for-ai/ai-exposes-data-governance-debt/) and [why data governance implementations fail](https://atlan.com/know/ai-agent/ai-agent-governance/why-data-governance-implementations-fail/). For a governance lead, the practical test is simple: can software evaluate this rule on every request an agent makes?

---

## Which data governance policies should you write as code first?

Start with rules that have a clear yes or no answer and a high cost when they fail, such as who may see a card number. Retention and classification rules suit code later, once the first rules have an owner and a test.

### Six policy types to start with

| Policy type | Example rule | Where it runs | Source |
|---|---|---|---|
| Access | Only members of a named group may query a table | Query engine or access layer | [Atlan data policies](https://docs.atlan.com/product/capabilities/governance/access-control/data-policy) |
| Masking and row filters | Show only the last 4 characters of any column tagged as a card number, and mask the rest | Query time, driven by a tag | [Tag-based masking in a cloud data warehouse](https://docs.snowflake.com/en/user-guide/tag-based-masking-policies) |
| Classification and tagging | Tag a column as personal data when it matches an approved pattern | Scan or ingestion | [Data classification and tag management for AI](https://atlan.com/know/ai-agent/data-for-ai/data-classification-and-tag-management-for-ai/) |
| Retention | Archive records after the period the written policy states | Scheduled job | Your retention policy and its owner |
| Data quality and contracts | A table must keep its agreed columns and types | Pull request and publish | [Atlan data contracts](https://docs.atlan.com/product/capabilities/governance/contracts/how-tos/create-data-contracts) |
| Certification before use | Only certified assets are offered to an agent | Wherever your agent reads data | [What is data certification](https://atlan.com/know/ai-agent/ai-agent-governance/what-is-data-certification/) |

The masking row shows classification driving enforcement: the warehouse documentation says a masking policy set on a tag protects tagged columns automatically, so one rule covers many columns, as long as the column's data type matches the type the masking policy is written for. That feature requires an Enterprise edition of that warehouse, so check yours.

### What stays with people

What stays with people: exceptions, trade-offs and the purpose behind a policy. A small estate can also do a lot with reviewed documents and one spreadsheet, and moving to code earns its cost when volume and the number of enforcement points grow. [Types of metadata for AI agents](https://atlan.com/know/ai-agent/data-for-ai/types-of-metadata-for-ai-agents/) and [data contracts for AI](https://atlan.com/know/ai-agent/data-for-ai/data-contracts-for-ai/) show which signals each rule can rely on.

---

## How do you apply policy as code in seven steps?

Seven steps take a written policy to an enforced, logged rule, and the last two keep it current.

### Step 1. Write the business statement once

Write the policy in business words: what it protects, who owns it, which data it covers and when it is reviewed. In Atlan, a Policy Center policy carries owners, a purpose, scope filters and a validity and review period, per the [policy creation docs](https://docs.atlan.com/product/capabilities/governance/stewardship/how-tos/create-policies). The statement is the anchor for everything below, so a rule never has to explain itself without one. A [business glossary](https://atlan.com/know/ai-agent/how-to-manage-kpi-definitions-and-a-business-glossary-in-a-data-catalog/) keeps the terms in the statement consistent.

### Step 2. Translate it into one rule and keep the link

Express the statement as a rule, or a small set of rules, in a declarative language such as Rego, the language OPA documents, or Cedar. Keep a reference from the rule to the statement, such as a structured annotation holding the policy's identifier, and add a check in your pull request pipeline that fails when it is missing. If you run Cedar's schema validation, a malformed rule fails when you create or update it. [Rule management](https://atlan.com/know/ai-agent/ai-agent-governance/rule-management-data-governance/) describes the business-rule side of this translation.

### Step 3. Store it in Git with a named reviewer

A rule changes only through a reviewed change. A cloud provider's [policy as code guidance](https://learn.microsoft.com/en-us/azure/governance/policy/concepts/policy-as-code) recommends keeping policy definitions in source control, and Atlan's contract flow works the same way: commit contract files to version control, validate on pull request and publish on merge, using `atlan validate contract -f` and `atlan push contract -f`, as the [CLI documentation](https://docs.atlan.com/product/capabilities/build-apps/sdks/python/data-contracts/how-tos/manage-via-cli) describes. Name the reviewer who can read both the rule and the business statement.

### Step 4. Test it

Test requests that should pass, requests that should be denied, edge cases and requests with missing context. OPA ships a [testing framework](https://www.openpolicyagent.org/docs/policy-testing) where tests are rules prefixed `test_`, run with `opa test`. The cloud provider guidance says to test a compliant resource, a non-compliant resource and a missing property. 

A rule that passes tests has met the cases you thought of, which is why the next step exists. Atlan's documentation covers contract validation, not a test runner for access rules, so run these tests in the engine that evaluates the rule.

### Step 5. Run it in audit mode before you enforce

Audit mode records what the rule would have done without blocking anything. The cloud provider guidance describes this as an enforcement mode set to disabled, where resource creation and updates are not blocked while existing resources are still evaluated, then enabled one environment at a time after validation. 

That guidance covers cloud resources, so read it as the pattern to copy. For a data rule it means evaluating the rule and recording the result without acting on it, where your engine allows that. [Graduated trust models](https://atlan.com/know/ai-agent/ai-agent-governance/graduated-trust-models-data-governance/) use the same idea: widen enforcement as evidence builds.

| Stage | Mode | What you watch |
|---|---|---|
| 1. Test environment | Audit only | Would-be denials, and whether each one is correct |
| 2. Production, audit only | Audit only | Would-be denials on real traffic, and who they affect |
| 3. One team or domain | Enforce | Complaints, exceptions requested, and any denial with no owner |
| 4. Everyone | Enforce | Denial rate against the audit baseline |

### Step 6. Enforce and log every decision

Once enforcement is on, record each decision. OPA [decision logs](https://www.openpolicyagent.org/docs/management-decision-logs) carry a decision ID, the policy path, the input, the result, the bundle revision and a timestamp, which supports auditing and offline debugging. A decision log answers the audit question directly: which rule, which input, which outcome. Atlan's documentation does not describe a per-decision log for access policies, so confirm where your enforcement point records decisions.

| Field | What it answers |
|---|---|
| Decision ID | Which single decision is this |
| Path or rule | Which rule ran |
| Input | What was asked, as your engine defines it: for example user, asset, purpose |
| Result | The outcome your engine records, such as allow or deny |
| Revision | Which version of the rule decided |
| Timestamp | When it happened |

### Step 7. Review when something changes

A yearly review misses the day things change. 

Keep the calendar review, and add triggers: review when the rule changes, when an asset appears with no policy, and after an audit finding. Atlan's Policy Center shows an ungoverned assets count, the active assets with no governing policy, and deprecates a policy when its validity period ends, as the [policy management docs](https://docs.atlan.com/product/capabilities/governance/stewardship/how-tos/manage-policies) describe. OPA's [bundle mechanism](https://www.openpolicyagent.org/docs/management-bundles) keeps the last good bundle when a new one fails to activate, so a bundle that fails to load does not leave the engine with no policy. [Human on the loop](https://atlan.com/know/ai-agent/ai-agent-governance/human-on-the-loop-data-governance/) covers how people supervise the exceptions this review surfaces, and [AI-ready data owners and stewards](https://atlan.com/know/ai-agent/ai-ready-data/ai-ready-data-owners-and-stewards/) covers who does the reviewing.

---

## How is policy as code different from a policy document or a role grant?

A policy document says what should happen, a role grant says who may, and policy as code is the rule that decides each request.

| Approach | Strength | What it cannot show alone |
|---|---|---|
| Policy document | Carries the intent, the owner and the reasoning | Whether anything enforces it |
| Role grant | Simple, fast to audit for who has access | Why access was given, or which purpose it serves |
| Policy as code | Decides each request the same way and logs it | The business meaning, unless it links to the statement |

With only code, you lose the business meaning: the engineer who wrote the rule moves on and nobody remembers why it exists. With only documents, you lose enforcement. The two belong together, and [role-based access in a context layer](https://atlan.com/know/ai-agent/context-layer/context-layer-role-based-access-control/) shows how a role grant and a rule can share one view of the data. [DSPM compared with a catalog for AI agents](https://atlan.com/know/ai-agent/ai-agent-governance/dspm-vs-data-catalog-ai-agents/) adds a third angle on where enforcement signals come from.

### Does policy as code replace governance tools?

No. It is the enforcement layer of a governance program, and the policy record, the owner and the scope still need a home.

---

## What common mistakes break policy as code in data governance?

The failures practitioners meet most often sit on the people side of the rule, not in the language.

### Is policy as code only for technical teams?

No, and treating it that way is the first mistake. The owner cannot read the code, so the person who approves the policy approves something they cannot check. 

A reviewer who reads both the statement and the rule fixes that. A rule with no dry run blocks the wrong people on day one; the audit stage above prevents it. A rule with no owner outlives its purpose, and nobody dares to remove it.

A correct rule can also fail for lack of context. If the enforcement point has no classification, user attributes or purpose, the rule cannot decide, and the fix is metadata, not more code; [metadata management for AI](https://atlan.com/know/ai-agent/data-for-ai/metadata-management-for-ai/) covers that foundation. Tests do not prove intent either: the cloud provider guidance says the enforcement mode setting is "not a replacement for thoroughly testing," and Cedar's schema validates policies only when you create or update them, not when a request is evaluated.

### Can policies be rolled back safely?

Rolling a rule back works like any other change. Because the rule lives in version control, a revert goes through the same review, and where your pipeline publishes on merge, as Atlan's contract flow does, the earlier version is published again.

Last, policies spread across repositories and engines until nobody has the full picture. The [data governance operating model](https://atlan.com/know/ai-agent/data-governance-operating-model/) and [lessons from failed implementations](https://atlan.com/know/ai-agent/ai-agent-governance/why-data-governance-implementations-fail/) show how teams keep that sprawl in check, and an [AI center of excellence](https://atlan.com/know/ai-agent/ai-agent-governance/how-to-build-ai-center-of-excellence/) is one place to hold the shared rule set.

---

## How does Atlan support policy as code?

Atlan's AI Context Platform holds the business policy, the access rules and the data contracts in one context layer, and each is managed the way its documentation describes. Rule evaluation, tests and decision logs run in the engine you choose.

| Need | Atlan feature | How it is managed | Source |
|---|---|---|---|
| Business policy record | Policy Center: owners, scope, compliance rules, approval, statuses, ungoverned assets count | In the product, with approval workflows | [Policy docs](https://docs.atlan.com/product/capabilities/governance/stewardship/how-tos/automate-policy-compliance) |
| Access and masking | Data policies in personas and purposes | In the product; the Python SDK can retrieve, update and delete persona and purpose policies | [SDK docs](https://docs.atlan.com/product/capabilities/build-apps/sdks/python/access-control/how-tos/manage-policies) |
| Data contracts | YAML contract template with CLI commands to initialize, validate, push and sync | From Git: validate on pull request, push on merge | [CLI docs](https://docs.atlan.com/product/capabilities/build-apps/sdks/python/data-contracts/how-tos/manage-via-cli) |

### What Atlan documents for each step

Against the seven steps, Atlan's documentation covers the written policy and its owners (step 1), contracts managed from Git (step 3 for contracts) and the ungoverned-assets and expiry review (step 7). Writing rules in a language, running tests, audit-mode rollout and decision logs (steps 2, 4, 5 and 6) happen in the engine that evaluates the rule. 

### Data policies and the hard deny

Data policies cover the querying and retrieval of data, with masking options of show first 4, show last 4, hash, nullify and redact. Atlan's documentation states that "an explicit deny is a hard ceiling that no role or approval can override," so a deny written once holds across roles. Data policies are not enabled by default, so an admin turns them on. Contracts support tables, views and materialized views, and the CLI page marks data contracts as limited availability.

### How the pieces connect

The Policy Center record sits beside terms, owners and lineage, so the person and purpose behind a rule stay one click from the rule's subject. See the [context layer for data governance teams](https://atlan.com/know/ai-agent/context-layer-for-data-governance-teams/), the [context layer reference architecture](https://atlan.com/know/ai-agent/context-layer/context-layer-reference-architecture/) and the [AI Context Platform](https://atlan.com/know/ai-agent/context-layer/ai-context-platform/) overview. [Context layer evaluation criteria](https://atlan.com/know/ai-agent/context-layer/context-layer-evaluation-criteria/), a [model-agnostic context layer](https://atlan.com/know/ai-agent/context-layer/model-agnostic-context-layer/), the [agent context layer](https://atlan.com/know/agent-context-layer/) and [data lineage for AI](https://atlan.com/know/ai-agent/data-for-ai/data-lineage-for-ai/) explain how the pieces fit, and [MCP for data governance](https://atlan.com/know/ai-agent/ai-agent-governance/mcp-for-data-governance/) covers how agents read the same policies. The [dual plane of context and control](https://atlan.com/know/ai-agent/context-layer/dual-plane-of-context-and-control/) names the pairing of what an agent knows and what it may do.

---

## Where code ends and ownership begins

A rule written as code applies the same logic to the same inputs, and that is its value. Whether the rule is right is a different question, and the policy owner has to answer it.

Atlan's approach follows from that split: the business statement, its owners and its scope live in Policy Center, and the code is the enforcement layer. Related reading: [what makes data AI-ready](https://atlan.com/know/ai-agent/data-for-ai/what-makes-data-ai-ready/), [how a context layer controls hallucination](https://atlan.com/know/ai-agent/context-layer/how-context-layer-controls-hallucination/), [AI agent memory governance](https://atlan.com/know/ai-agent-memory-governance/), [systems of semantics](https://atlan.com/know/ai-agent/data-for-ai/systems-of-semantics/), the [data governance platform evaluation criteria](https://atlan.com/know/data-governance/data-governance-platform-evaluation-criteria/), and the [Critical Capabilities explainer](https://atlan.com/know/gartner/critical-capabilities-for-data-governance-2026/).

---

## FAQs about policy as code in data governance

Seven questions come up most when teams start.

### 1. What is policy as code in data governance?

Policy as code is a governance rule written as code, often in a declarative language, kept in version control and evaluated by software instead of read by a person. In data governance the rule is about a column, a table, a tag or a purpose, and a named owner still approves the business meaning.

### 2. What is an example of policy as code for data?

A masking rule that shows only the last 4 characters of any column tagged as a card number, for everyone outside a named group. The tag drives the rule and the rule sits in version control. Where your engine writes a decision log, each show or mask decision is recorded.

### 3. How do you test policy as code?

Write test cases for requests that should be allowed, requests that should be denied, edge cases and requests with missing context, then run them on every change. After the tests pass, run the rule in audit mode, where it records outcomes without blocking anything, before you enforce it.

### 4. How is policy as code different from infrastructure as code?

Infrastructure as code describes the systems you want to exist. Policy as code describes the rules those systems and the data inside them must follow. Both live in version control and get reviewed, but a data rule also needs classification, ownership and purpose to decide each request.

### 5. Who owns a policy that is written as code?

A business owner owns the policy statement, and an engineer or steward owns the rule that implements it. Record both names, and link the rule back to the statement, and review them together whenever either one changes.

### 6. Can AI agents follow policy as code?

Yes, when the rule is evaluated at the moment of access. Agents act under a person's or service account's identity, so the system can check the rule against each request. Decide how an agent acts on behalf of a user and which purpose each call carries, since identity alone does not settle that.

### 7. What should you not put in code?

Keep the purpose of a policy, the trade-offs behind it and the handling of exceptions with people. Code is good at checks with a clear answer. Route a rare request whose justification needs judgment to the policy owner, through a recorded exception.

---

## Sources

1. [Open Policy Agent documentation](https://www.openpolicyagent.org/docs)
2. [Policy testing, Open Policy Agent documentation](https://www.openpolicyagent.org/docs/policy-testing)
3. [Decision logs, Open Policy Agent documentation](https://www.openpolicyagent.org/docs/management-decision-logs)
4. [Bundles, Open Policy Agent documentation](https://www.openpolicyagent.org/docs/management-bundles)
5. [Cedar policy language reference](https://docs.cedarpolicy.com/)
6. [Design policy as code workflows, a cloud provider's documentation, updated December 2025](https://learn.microsoft.com/en-us/azure/governance/policy/concepts/policy-as-code)
7. [Tag-based masking policies, a cloud data warehouse's documentation](https://docs.snowflake.com/en/user-guide/tag-based-masking-policies)
8. [Policy-as-Prompt, arXiv 2509.23994](https://arxiv.org/abs/2509.23994)
9. [Progent: Securing AI Agents with Privilege Control, arXiv 2504.11703, preprint](https://arxiv.org/abs/2504.11703)
10. [Data policies, Atlan documentation](https://docs.atlan.com/product/capabilities/governance/access-control/data-policy)
11. [Manage access policies with the Python SDK, Atlan documentation](https://docs.atlan.com/product/capabilities/build-apps/sdks/python/access-control/how-tos/manage-policies)
12. [Create data contracts, Atlan documentation](https://docs.atlan.com/product/capabilities/governance/contracts/how-tos/create-data-contracts)
13. [Manage data contracts with the CLI, Atlan documentation](https://docs.atlan.com/product/capabilities/build-apps/sdks/python/data-contracts/how-tos/manage-via-cli)
14. [Create policies, Atlan documentation](https://docs.atlan.com/product/capabilities/governance/stewardship/how-tos/create-policies)
15. [Manage policies, Atlan documentation](https://docs.atlan.com/product/capabilities/governance/stewardship/how-tos/manage-policies)
16. [Automate policy compliance, Atlan documentation](https://docs.atlan.com/product/capabilities/governance/stewardship/how-tos/automate-policy-compliance)
17. Gartner, Magic Quadrant for Data and Analytics Governance Platforms, 12 November 2026, Anurag Raj Et Al.

Gartner does not endorse any company, vendor, product or service depicted in its publications, and does not advise technology users to select only those vendors with the highest ratings or other designation. Gartner publications consist of the opinions of Gartner's business and technology insights organization and should not be construed as statements of fact. Gartner disclaims all warranties, expressed or implied, with respect to this publication, including any warranties of merchantability or fitness for a particular purpose.

Gartner and Magic Quadrant are a trademark of Gartner, Inc., and/or its affiliates.

## Next steps

- To see Atlan's context layer in action first, watch a recorded demo: [Atlan context layer demos](https://atlan.com/context-layer-demo/)
- To see Atlan working on your own data stack, book a demo: [Book a demo with Atlan](https://atlan.com/forms/talk-to-sales-contact/)
