Resolve Calculated Policy Evaluation Errors

In this guide, you will identify and resolve a calculated policy evaluation error using the Guardrails console.

A Calculated Policy dynamically determines policy settings by sourcing CMDB data, executing a GraphQL query, and applying a Nunjucks template to generate a resource-specific policy value. Any policy setting can be calculated, making policies more context-aware and adaptable.

However, calculated policies can encounter errors due to misconfigurations or data inconsistencies, leading to controls entering an error state. Ensuring these policies are properly configured and promptly fixed is crucial for maintaining compliance and system stability.

Prerequisites

Step 1: Find the Policy Values in Error

Calculated values that fail template rendering show as error. Open the calculated policy setting and select its Values tab (or filter the Policies Values view by State: Error) to see the affected resources. Each shows a Template render error.

Policy setting Values tab showing every bucket in error with a Template render error message

Step 2: View the Error Details

Click a value row to open its Policy Value page. The Value panel is marked ERROR and CALCULATED, and shows the full error message. In this example, Unable to call $["bucket"]["turbot"]["tags"]["nonExistentTag"]["toString"], which is undefined or falsey, which tells you the template is accessing a property that doesn't exist on the resource.

Policy Value page showing the error and calculated badges with the full template render error and the settings hierarchy

Step 3: Edit the Policy Setting

In the hierarchy, open the effective calculated setting and click Edit. The Update Policy Setting form opens in calculated mode, showing the input query and template. Click Launch calculated policy builder to open the builder.

Update Policy Setting form in calculated mode with the input query and the Launch calculated policy builder link

Step 4: Identify the Error in the Builder

The builder opens with the existing query and template. Pick a Test Resource in Step 1 if one isn't already selected. The Output panel under Step 3 is highlighted in red and shows the render error, confirming which line of the template is failing.

Calculated Policy Builder showing the broken template with the Output panel highlighted red and the render error

Step 5: Fix the Template

Correct the Nunjucks template in the Step 3 panel. When the fix is valid, the Output panel turns green and Step 4 shows the transformed value passing the policy type schema. Click Update to return to the settings form.

Calculated Policy Builder with the corrected template producing a green Output of Check: Enabled and a valid Step 4 result

Back on the Update Policy Setting form, review the corrected template and click Update.

Update Policy Setting form showing the corrected template on the Template tab and the Update button

Step 6: Verify the Fix

After saving, the policy value re-evaluates. Confirm on the Policy Value page that the value transitions from error to a valid state (for example Check: Enabled), which confirms the calculated policy is now producing the correct output.

Policy Value page showing the resolved Check: Enabled value with the calculated setting as effective

Troubleshooting

IssueSolution
Template references an undefined propertyCheck the GraphQL query result to verify the data structure. Use conditional checks (for example {%- if $.bucket.turbot.tags.myTag -%}) to handle missing properties.
Template produces an invalid valueThe output must be one of the valid values for the policy type. Check for typos, since values are case-sensitive.
Policy value stays in error after savingUse the value's Actions menu to re-run it, and check the Activity or logs for process details.
Further assistanceOpen a Support Ticket