AI governance principles: how to enforce each one in code

Seven AI governance principles mapped to controls that run on every LLM request, the error each returns, and the one principle a gateway cannot enforce.

Published
Reading time
11 min read
Level
Intermediate
By
AI for Devs
TL;DR
  • AI governance principles become enforceable when each one maps to a check on every LLM request that returns a specific error or leaves a specific record.
  • Six common principles (accountability, transparency, privacy, safety, cost control, auditability) can be enforced at one choke point, an AI gateway, through keys, logs, redaction, guardrails, budgets, and audit logs.
  • Fairness cannot be enforced per request by a gateway or any proxy, because it is measured across groups of outcomes; it needs an offline evaluation set and a release gate.
  • In Bifrost, virtual keys, budgets, rate limits, and request logs are open source; guardrails, role-based access control, and signed audit logs are Enterprise features, as of November 23, 2026.

AI governance principles are the commitments a company makes about how it uses AI: who is accountable, what gets recorded, which data stays private, and what the system must never do. Most lists agree on the core, but a principle on a slide does not stop a request. This article maps seven common principles to controls that run on LLM traffic, names the error or record each control produces, and says where a gateway cannot help. The worked example is Bifrost, an open-source AI gateway written in Go.

This piece sits between two related ones. The AI compliance framework article covers the process side (owners, reviews, evidence), and AI governance and compliance covers the regulations. Here the subject is the code.

#What AI governance principles mean for LLM traffic

An AI governance principle is enforceable when an engineer can name the request field it checks, the error it returns, and the log line it leaves. The OECD AI Principles, adopted in 2019, updated in May 2024, and backed by 47 adherents, list transparency, robustness and safety, accountability, and human rights including fairness and privacy. The NIST AI RMF lists similar characteristics, from "privacy-enhanced" to "fair with harmful bias managed." A 2020 Berkman Klein Center review of 36 principles documents found the same themes recurring.

Engineering teams usually add two more: cost control and auditability. Reduced to the question a system has to answer on each request, the seven look like this:

PrincipleQuestion per requestControlEvidence it leaves
AccountabilityWhich team or service sent this call?Per-team key, required headers401 without a key; owner on every log entry
TransparencyCan the prompt and response be reconstructed?Request loggingFull log entry with model, tokens, cost
PrivacyDid personal data or secrets leave the boundary?Redaction, content-logging controlsPlaceholders in place of values
SafetyWas harmful input or output stopped in flight?Input and output guardrails400 with a guardrail error type
FairnessAre comparable people treated the same way?Offline evaluation (no per-request control)Per-group scores, release decision
Cost controlIs there a hard ceiling on this caller's spend?Budgets and rate limitsBlocked call once a limit is hit
AuditabilityWho changed the rules, and when?Signed audit log, role-based accessSigned before-and-after diff

Six of these are properties of a single request or a single configuration change. Fairness is a property of outcomes across many requests, which is why it gets its own section below.

Seven AI governance principles against six gateway controls: six principles have at least one enforcing control, and fairness only gets a sample of logged trafficAccountableTransparentPrivacySafetyFairnessCostAuditableVirtual keysopen sourceowner IDcontent offtool filterper-key capBudgets, limitsopen sourcehard capAccess controlEnterpriserolesdata scopewho editsGuardrailsEnterpriseredactionblock 400Request logsopen sourceattributionfull recordeval samplespendAudit logsEnterpriseadmin actorsigned diffoffline evalsenforces it per requestsupplies evidence onlyno role
Fig. 1Every principle except fairness has at least one control that enforces it per request. Fairness gets only a sample of logged traffic, and the rows marked Enterprise are paid features in Bifrost.

#One enforcement point: the AI gateway

Controls that live inside each application drift apart, so the usual design puts one AI gateway in front of every model provider and enforces the principles there. Each sanctioned request takes the same path, so a policy written once applies to all of them.

Bifrost fills that role with one OpenAI-compatible API in front of 10,000+ models across 25+ providers, and it governs MCP tool calls and agent traffic on the same path. The core is Apache 2.0 and self-hosted; the governance resource page gives an overview of its access and spend controls. Figure 2 shows the checks one request clears and the records it leaves.

A request clears a virtual key check, required headers, budgets and rate limits, and an input guardrail before the provider, then an output guardrail; the request log records it, and admin config changes go to a signed audit logbefore the modelClientsk-bf-* keyVirtual key401 virtual_key_requiredRequired headers400 missing_required_headersBudgets, rate limitsblocked when exhaustedInput guardrail400 guardrail_interventionProvidermodel callOutput guardrail400 or monitorResponseRequest logmetadata always; content per keyredaction applies before storageAdminconfig editAudit logHMAC-signed before/after diff
Fig. 2A request clears identity, header, budget, and guardrail checks before the provider sees it, and each check has its own error. Traffic lands in the request log; changes to the rules themselves land in a separate signed audit log.

A gateway governs only the traffic sent to it. A developer whose coding agent talks straight to a provider is outside every control in this article, which is the problem shadow AI describes. Bifrost Edge closes that gap: it runs on employee machines, routes AI apps, browser AI, coding agents, and their MCP servers to the Bifrost gateway, and applies the same keys, budgets, and guardrails on endpoint traffic with nothing configured per device. Edge requires the Enterprise gateway.

#Accountability: every request has an owner

Accountability means no LLM call is anonymous. The control is a credential per team, service, or customer, plus a rule that rejects any request arriving without one.

In Bifrost that credential is a virtual key. A key belongs to one team or one customer (team_id and customer_id are mutually exclusive), and its metadata pairs, such as a cost center or an owner address, are copied onto every log entry made with it. Clients send it in the x-bf-vk header or in the provider-style header their SDK already uses.

Keys are optional until enforcement is on. Two client settings close the anonymous path and add attribution beyond the key:

config.json
JSON
{
  "client": {
    "enforce_auth_on_inference": true,
    "required_headers": ["x-tenant-id", "x-correlation-id"]
  }
}

With enforcement on, a call without a key fails with 401 and virtual_key_required, and an inactive or expired key fails with 403 and access_blocked. Required headers reject a request missing any listed header with 400 and missing_required_headers, before it reaches a provider. Setting expires_at on a key gives contractors and short projects a credential that stops on a set date.

Access scope is part of accountability too. Providers are deny-by-default on a key: a provider not listed in its provider_configs is unreachable, and allowed_models narrows each listed provider further. A key meant for one small model cannot reach a frontier model by changing a string in the request.

#Transparency: reconstruct what the model saw

Transparency, for an engineering team, means any production request can be pulled up with its prompt, response, model, and cost. Without that record, explaining a bad answer to a customer or an auditor is guesswork.

Bifrost's built-in observability records the conversation history, the response and tool calls, the provider and model that served it, parameters, token usage, cost, latency, and status. It writes to SQLite by default and to PostgreSQL for production volume, and the logging plugin runs asynchronously, adding under 0.1 ms in Bifrost's own benchmark. The same data can go to OpenTelemetry, Datadog, Prometheus, Kafka, BigQuery, Pub/Sub, or Splunk, so LLM calls sit next to the rest of a service's traces.

Transparency toward end users is a separate job. Telling a user that a model wrote an answer, or explaining why an application was flagged, belongs in the product. The gateway supplies the record those explanations rest on.

#Privacy: sensitive data stops at the boundary

Privacy on LLM traffic has two paths to cover: personal data and secrets leaving the network inside prompts, and the company's own logs becoming a second copy of that data.

On the request path, Bifrost Enterprise guardrails can redact instead of block, in three redaction modes:

  • runtime rewrites the live request or response, so the provider never sees the value, and logs keep the redacted text.
  • logs_only leaves the live content alone, so the model gets the real value, but logs and trace exports store placeholders.
  • runtime_reversible redacts the live content with reversible placeholders that authorized users can reveal in Bifrost logs.

Detection comes from Custom Regex (with a PII template), Secrets Detection, Microsoft Presidio, Azure AI Language PII, and a few partner providers. The mode choice is a privacy decision: runtime when the provider must never see the value, logs_only when the model needs it but storage should not keep it.

On the logging path, content logging decides whether bodies are stored at all. disable_content_logging: true on a virtual key that carries health or financial data keeps only metadata (model, provider, tokens, cost, latency, status, and attribution IDs). Each export connector has its own flag that does not inherit the client setting, so check every destination.

#Safety: block harmful input and output in flight

Safety means a prompt injection, a jailbreak, or an unsafe response is stopped while the request is in flight, not found in a log review a week later. That takes guardrails on both input and output, applied by rule.

Bifrost splits this into rules and profiles. A rule decides when to check, with a CEL expression, an apply_to value of input, output, or both, and a target of llm or mcp. A profile decides how, through a Bifrost-managed check or a provider such as AWS Bedrock Guardrails, Azure Content Safety, or Google Model Armor. An abridged rule:

guardrail rule (abridged)
JSON
{
  "name": "Screen prompts on the support assistant",
  "enabled": true,
  "target": "llm",
  "cel_expression": "team == \"support\"",
  "apply_to": "input",
  "sampling_rate": 100,
  "provider_config_ids": [1, 2]
}

CEL can test model, provider, headers, virtual_key, team, customer, and user, so a stricter policy can apply only to external-facing traffic. A block returns HTTP 400 with "type": "guardrail_intervention"; for an input rule the request never reaches the model, and for an output rule the error replaces the response. Setting output_mode to monitor lets a new output rule record what it would have caught without blocking, which is the safe way to tune it.

One trade-off to plan for: when a profile errors or times out, it fails open and the next linked profile still runs. A check that must never be skipped needs a second profile behind it.

Agents add a second surface. Rules with target: "mcp" inspect tool arguments before a tool runs and its result after, and MCP tool filtering on a virtual key is deny-by-default: a key with no MCP configuration gets no tools, except from clients an admin marks Allow by Default. A support agent that reads tickets has no reason to reach a tool that deletes them. The AI security policies article turns these controls into written policy.

#Fairness: the principle a gateway cannot enforce

Fairness cannot be enforced per request by a gateway or by any other proxy. Whether a system treats comparable people the same way shows up only when outcomes are compared across groups, and one request carries no information about how similar requests were handled. NIST's framework makes a related point: fairness standards vary across cultures and applications, and mitigating harmful bias does not by itself make a system fair.

Fairness is enforced in the evaluation process instead:

  1. Define the groups and outcomes that matter for the use case, such as approval rates by region or answer quality by language.
  2. Build an evaluation set with matched cases across those groups, including counterfactual pairs that differ only in an attribute such as a name.
  3. Score outputs per group, never only in aggregate, so a strong average cannot hide a weak slice. An LLM judge can score open-ended answers if it is itself checked against human labels.
  4. Write down the acceptable gap before testing, and block a model or prompt change when the gap exceeds it.
  5. Route high-stakes decisions to human review and record the reviewer's call.
Fairness is checked offline: request logs feed an evaluation set of matched pairs, outputs are scored per group, and a gap over the agreed limit blocks the releasegatewayevaluation, outside the request pathRequest logssample real trafficEval setmatched pairs by groupScore per groupnever only the averageGap checklimit set in advanceShipBlock releaseOne request carries no comparison between groups,so no per-request check can measure a fairness gap.Human review for high-stakes decisions
Fig. 3The fairness check happens after the traffic, not during it. The gateway's only part is the logged sample on the left; the per-group scoring and the gap limit decide whether a change ships.

The gateway still helps at the edges. Its request logs are a sample of real production traffic to draw cases from, and allowed_models on each virtual key means a model swap goes through a reviewable config change rather than a code edit, so last month's fairness results are not silently invalidated. The LLM evaluation guide covers building the eval suite itself.

#Cost control: spend has a hard ceiling

Cost control means every caller has a spending limit the system enforces, not a dashboard someone reads at month end. A runaway agent loop or a leaked key should hit a limit within minutes.

Bifrost sets budgets and rate limits at four levels: customer, team, virtual key, and provider config. A request has to clear every budget that applies to it. Each budget has a max_limit in USD and a reset_duration such as 1d, 1w, 1M, or 1Q, and rate limits cover requests and tokens separately:

config.json (excerpt)
JSON
{
  "budgets": [
    { "id": "budget-eng-vk", "max_limit": 500.0, "reset_duration": "1M", "virtual_key_id": "vk-001" }
  ],
  "rate_limits": [
    {
      "id": "rate-limit-eng-vk",
      "token_max_limit": 10000,
      "token_reset_duration": "1h",
      "request_max_limit": 100,
      "request_reset_duration": "1m"
    }
  ]
}

Limits on a provider config behave differently from limits on the key: when one provider exceeds its limits, it is excluded from routing and the key keeps working through its other providers. That makes a per-provider cap a cost control and a reliability control at once.

Pair each cap with an early warning. Bifrost Enterprise alert rules are CEL expressions over usage metrics, scoped to a virtual key, team, or customer; budget_usage_percent >= 80.0 notifies Slack, Microsoft Teams, PagerDuty, or a webhook well before calls start failing.

#Auditability: policy changes leave a signed trail

Auditability means proving who changed a governance rule, what changed, and when, with a record nobody can quietly edit. Request logs cover what traffic did; the audit log covers what administrators did to the controls.

Bifrost Enterprise audit logs write an event for every create, update, and delete on the management API, including changes to /api/config. Events are named <resource>.<verb>, such as virtual_key.updated, and carry a before-and-after diff with secret fields marked redacted: true. Every row is signed with HMAC-SHA256, and GET /api/governance/audit-logs/{id}/verify checks a signature. Turning audit logging off is itself recorded, as a high-severity audit.logging_disabled event on the next boot.

Retention is a decision to make before an auditor asks. retention_days sets how long rows stay in the database, and the docs recommend S3 Object Lock or another write-once bucket for the archive. Exports come as JSON, JSON Lines, or Syslog (RFC 5424) for a SIEM.

An audit trail is only as strong as the access model behind it. Role-based access control ships Admin, Developer, and Viewer roles, plus custom roles built from resource and operation pairs such as GuardrailsConfig or AuditLogs. Roles map from identity provider groups, app roles, or claims, and a user's role is rechecked at every sign-in, session refresh, and SCIM push, so removing someone from a group in Okta or Entra removes their admin rights without manual cleanup.

#An enforcement order that breaks the fewest callers

Roll the controls out from visibility to blocking, so nothing is restricted before it has been seen:

  1. Route all LLM traffic through the gateway with logging on, and watch who calls what for two weeks.
  2. Issue a virtual key per team or service, then turn on enforce_auth_on_inference once every caller has one.
  3. Size budgets and rate limits from the logged usage, with an alert below each cap.
  4. Set redaction modes and disable_content_logging on keys that carry regulated data, and check each export connector.
  5. Run new output guardrails in monitor mode, review what they would have blocked, then switch them to blocking.
  6. Turn on audit logs and map roles to identity provider groups before widening admin access.
  7. Stand up the fairness evaluation set and make it a release gate for model and prompt changes.
  8. Extend the same policy to laptops with Edge, so coding agents and desktop AI apps stop bypassing steps 2 to 6.

Each step leaves a config field that can be tested in CI or an error type that can be alerted on, which is the practical test of whether a principle is enforced or only written down. Product details here describe Bifrost as of November 23, 2026.

#Questions

What are the core principles of AI governance?

Most published lists share the same core: accountability, transparency, privacy, safety and security, and fairness. The OECD AI Principles, adopted in 2019 and updated in May 2024, and the NIST AI Risk Management Framework both include them. Engineering teams usually add cost control and auditability, because those are the principles that break first when LLM traffic grows without limits or records.

What is the difference between AI governance principles and an AI governance framework?

Principles are the values a company commits to, such as accountability or privacy. A framework, such as the NIST AI RMF or ISO/IEC 42001, is the process that puts them into practice: roles, risk reviews, documentation, and audits. Controls are the third layer, the checks that run on each request. A principle with no control behind it is a statement, not a guarantee.

Can an AI gateway enforce fairness?

No. Fairness is a property of outcomes across groups of people, and a single request carries no information about how comparable requests were handled. A gateway can supply logged production traffic as raw material for an evaluation set, and it can pin which models a team may call. The fairness measurement itself runs offline, scored per group, as a release gate for model and prompt changes.

How do you enforce AI governance in code?

Put every LLM call behind one enforcement point, usually an AI gateway, and attach a check to each principle: a per-team key for accountability, request logs for transparency, redaction for privacy, guardrails for safety, budgets for cost, and signed audit logs for auditability. Each check should return a specific error or leave a specific record, so it can be tested in CI and alerted on in production.

Who is responsible for AI governance in an engineering organization?

Ownership is usually split. A governance or risk group sets the principles and the acceptable thresholds, the platform team runs the gateway and the controls, and each product team owns its keys, budgets, and evaluation sets. The split works only when every LLM request can be traced to one owning team, which is why per-team credentials come first in most rollouts.

Which AI governance controls are in open-source Bifrost?

As of November 23, 2026, virtual keys, budgets, rate limits, required headers, MCP tool filtering, and built-in request logging are in the open-source gateway. Guardrails and redaction, role-based access control with identity provider sync, alert rules, and signed audit logs are Bifrost Enterprise features. Bifrost Edge, which extends the same policy to employee machines, requires the Enterprise gateway.