Skip to main content

Context Layer 17 min read

How to Apply Policy as Code in Data Governance

Quick answer

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.

  • 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

Want the bigger picture?

Get the AI Context Stack

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, and you can download the free report from Atlan. 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.

Paste into a new chat

Use the skill at https://atlan.website/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.website/skills/governance-workflow-embed-check.md

For an agent

curl -fsSL https://atlan.website/skills/governance-workflow-embed-check.md
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 says OPA “decouples policy decision-making from policy enforcement,” and the Cedar language reference 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 supplies the categories the rule refers to, and the 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 and the 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 covers where each of those fires, and the broader pattern is in 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 and AI agent identity. Two research papers on arXiv point the same way: Policy-as-Prompt turns governance documents into a source-linked policy tree and runtime guardrails for agents, and Progent 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 and 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
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
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
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
Certification before use Only certified assets are offered to an agent Wherever your agent reads data 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 and 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. The statement is the anchor for everything below, so a rule never has to explain itself without one. A business glossary keeps the terms in the statement consistent.


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 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 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 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 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 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 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 describe. OPA’s bundle mechanism 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 covers how people supervise the exceptions this review surfaces, and 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 shows how a role grant and a rule can share one view of the data. DSPM compared with a catalog for 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 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 and lessons from failed implementations show how teams keep that sprawl in check, and an 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
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
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

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, the context layer reference architecture and the AI Context Platform overview. Context layer evaluation criteria, a model-agnostic context layer, the agent context layer and data lineage for AI explain how the pieces fit, and MCP for data governance covers how agents read the same policies. The 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, how a context layer controls hallucination, AI agent memory governance, systems of semantics, the data governance platform evaluation criteria, and the Critical Capabilities explainer.


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
  2. Policy testing, Open Policy Agent documentation
  3. Decision logs, Open Policy Agent documentation
  4. Bundles, Open Policy Agent documentation
  5. Cedar policy language reference
  6. Design policy as code workflows, a cloud provider’s documentation, updated December 2025
  7. Tag-based masking policies, a cloud data warehouse’s documentation
  8. Policy-as-Prompt, arXiv 2509.23994
  9. Progent: Securing AI Agents with Privilege Control, arXiv 2504.11703, preprint
  10. Data policies, Atlan documentation
  11. Manage access policies with the Python SDK, Atlan documentation
  12. Create data contracts, Atlan documentation
  13. Manage data contracts with the CLI, Atlan documentation
  14. Create policies, Atlan documentation
  15. Manage policies, Atlan documentation
  16. Automate policy compliance, Atlan documentation
  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.

Emily Winks

Written by

Emily Winks, Data Governance Expert

18+ years in information architecture, data governance, and enterprise data management

Published 20 Nov 2026, updated 20 Nov 2026

Bridge the context gap.
Ship AI that works.