Guardrails and Policy as Code
Guardrails keep usage within agreed limits without slowing engineers down. This lesson explains preventive, detective and corrective guardrails, how they are written and governed as policy as code, and how to introduce them in a sensible order.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish guardrails from approval gates.
- Compare preventive, detective and corrective guardrails.
- Explain the benefits of policy as code.
- Identify common cost guardrails.
- Describe the order for introducing and measuring guardrails.
Guardrails, not gates
A gate requires approval before work can proceed; a guardrail lets work proceed freely within limits and intervenes only when a limit is crossed. FinOps prefers guardrails, because the cloud's value comes from engineers being able to act quickly. Guardrails encode agreed rules, such as required tags or approved regions, so that compliance is automatic rather than dependent on review.
Three types of guardrail
Guardrails are classified by when they act. The following comparison sets out the three types.
Preventive, detective or corrective?
Policy as code
Policy as code writes guardrails as code that is stored in version control, reviewed through pull requests, tested and deployed automatically. Examples include Azure Policy definitions, AWS service control policies and tag policies, Google Cloud organization policies, Cloud Custodian policies and Open Policy Agent rules evaluated in pipelines.
Treating policies as code brings the benefits of software engineering: every change is reviewed and recorded, policies can be tested against sample resources before deployment, the same policy can be applied consistently across accounts, and rolling back a faulty policy is as simple as reverting a commit.
Policy as code
Common cost guardrails
The following list describes guardrails that organizations commonly implement for cost.
- Required tags: owner, environment and cost center on every taggable resource.
- Approved regions: deny resource creation in regions the organization does not use, which also limits damage from compromised credentials.
- Allowed instance types: restrict expensive families, such as large GPU instances, to approved accounts.
- Non-production limits: maximum instance sizes or budgets for sandbox and development accounts.
- Lifecycle requirements: storage buckets must have lifecycle rules; log groups must have retention set.
- Schedules: development resources must carry a schedule tag.
Introducing guardrails in order
A practical sequence starts with detective controls, so that teams can see and fix issues themselves and the rule can be tuned. Once the rule is understood and violations are rare, it can become preventive, for example denying creation without tags. Corrective automation is added where the fix is safe and agreed. Every guardrail needs a documented exception process, such as an exception tag approved by the FinOps or platform team, so that legitimate needs are not blocked.
The following diagram shows the order in which guardrails are introduced.

Introducing a guardrail
Measuring guardrails
Guardrails should be measured like any control: how many violations they find or prevent, how many exceptions are requested, how much cost they avoid and how often they block legitimate work. A guardrail that is constantly bypassed through exceptions probably needs redesign.
Tags that nobody applies
A tagging standard was published six months ago, but only 40% of new resources carry the owner tag. What sequence of guardrails should the platform team introduce?
First, add the tags automatically in shared infrastructure as code modules, so the easy path is compliant. Second, introduce a detective report of untagged resources per account, sent to account owners weekly. Third, after a communicated date, make the rule preventive, denying creation of taggable resources without an owner tag, with an exception process for special cases. Track compliance weekly through the transition.
The GPU sandbox
Data scientists in sandbox accounts sometimes launch the largest GPU instances and forget them, costing thousands of dollars. The organization does not want to slow experimentation. Which guardrails fit?
A preventive policy limiting sandbox accounts to approved, smaller GPU instance types, with an exception process for larger ones; a corrective rule that stops GPU instances idle for more than an hour; and a budget per sandbox account with alerts at 50% and 80% and, at 100%, an action that applies a restrictive policy. Experimentation remains self-service, while forgotten resources are caught quickly.
Classify: a daily report of resources without owner tags. Preventive, detective or corrective?
Show answer
Detective: it finds and reports the condition after it occurs but neither prevents nor fixes it.
Exam Tips
Remember for the exam
- Guardrails let work proceed within limits; gates require approval first.
- Preventive blocks, detective reports, corrective fixes.
- Policy as code is versioned, reviewed, tested and consistently applied.
- Start detective, move to preventive and corrective, and always provide an exception process.