Skip to content
Arxo Arxo

evaluate_policy

Evaluate architectural policies defined in your arxo.yaml configuration (or provided inline) and return any violations. This tool enables architecture governance by checking if current metrics meet your defined standards.

ParameterTypeRequiredDescription
project_pathstringYesAbsolute or relative path to the project root directory
policy_yamlstringNoInline policy YAML content (optional — uses arxo.yaml if not provided)

Returns a JSON summary with policy violations and current metric values.

{
"violations": [
{
"metric": "string", // Metric key (e.g., "scc.max_cycle_size")
"expected": "number", // Expected numeric threshold
"actual": "number", // Actual value from analysis
"operator": "string" // Comparison operator
}
],
"violations_count": "number",
"metrics_summary": [ // Current metric payloads from analysis
{
"id": "string",
"data": [ { "key": "string", "value": { "kind": "number", "v": 0.0 } } ]
}
]
}

Define policies in arxo.yaml:

policy:
invariants:
- metric: scc.max_cycle_size
op: '<='
value: 0
message: 'No circular dependencies allowed'
- metric: propagation_cost.system.ratio
op: '<='
value: 0.10
message: 'System propagation cost must stay under 10%'
- metric: smells.hubs.count
op: '=='
value: 0
message: 'No hub modules allowed'
OperatorDescription
==Equal to
!=Not equal to
<Less than
<=Less than or equal to
>Greater than
>=Greater than or equal to

Request:

{
"project_path": "."
}

Response:

{
"violations": [],
"violations_count": 0,
"metrics_summary": [
{
"id": "scc",
"data": [
{ "key": "scc.max_cycle_size", "value": { "kind": "number", "v": 0 } },
{ "key": "scc.cycle_count", "value": { "kind": "number", "v": 0 } }
]
},
{
"id": "smells",
"data": [
{ "key": "smells.hubs.count", "value": { "kind": "number", "v": 0 } },
{ "key": "smells.god_components.count", "value": { "kind": "number", "v": 0 } }
]
}
]
}

Request:

{
"project_path": "/path/to/project"
}

Response:

{
"violations": [
{
"metric": "scc.max_cycle_size",
"expected": 0,
"actual": 5,
"operator": "<="
},
{
"metric": "propagation_cost.system.ratio",
"expected": 0.10,
"actual": 0.23,
"operator": "<="
}
],
"violations_count": 2,
"metrics_summary": [
{
"id": "scc",
"data": [
{ "key": "scc.max_cycle_size", "value": { "kind": "number", "v": 5 } },
{ "key": "scc.cycle_count", "value": { "kind": "number", "v": 2 } }
]
},
{
"id": "propagation_cost",
"data": [
{ "key": "propagation_cost.system.ratio", "value": { "kind": "number", "v": 0.23 } }
]
}
]
}

Request:

{
"project_path": ".",
"policy_yaml": "policy:\n invariants:\n - metric: scc.max_cycle_size\n op: '<='\n value: 0\n message: 'No cycles allowed'\n - metric: centrality.module.betweenness_max\n op: '<'\n value: 0.5\n message: 'No modules with betweenness >= 0.5'"
}

Response:

{
"violations": [
{
"metric": "centrality.module.betweenness_max",
"expected": 0.5,
"actual": 0.62,
"operator": "<"
}
],
"violations_count": 1,
"metrics_summary": [
{
"id": "scc",
"data": [
{ "key": "scc.max_cycle_size", "value": { "kind": "number", "v": 0 } }
]
},
{
"id": "centrality",
"data": [
{ "key": "centrality.module.betweenness_max", "value": { "kind": "number", "v": 0.62 } }
]
}
]
}
policy:
invariants:
- metric: scc.max_cycle_size
op: '<='
value: 0
message: 'No circular dependencies allowed'
policy:
invariants:
- metric: propagation_cost.system.ratio
op: '<='
value: 0.15
message: 'System propagation cost must not exceed 15%'
policy:
invariants:
- metric: smells.hubs.count
op: '=='
value: 0
message: 'No hub modules allowed'
- metric: smells.god_components.count
op: '=='
value: 0
message: 'No god classes allowed'
policy:
invariants:
- metric: layer_violations.violations_count
op: '=='
value: 0
message: 'No layer violations allowed'
policy:
invariants:
- metric: sensitive_data_flow.pii_leaks
op: '=='
value: 0
message: 'No PII leakage to external services'
- metric: security.high_severity_cves
op: '=='
value: 0
message: 'No high-severity CVEs in dependencies'

Use this tool in a CI/CD pipeline:

1. evaluate_policy → check for violations
2. If violations_count > 0:
a. Fail the build
b. Comment on PR with violations
c. Link to get_hotspots or suggest_refactors for guidance
3. Else: proceed with merge

See Workflows: Policy enforcement for a full example.

ErrorCauseSolution
missing required parameter: project_pathproject_path not providedInclude project_path in request
Failed to parse policy YAMLInvalid YAML syntaxCheck YAML formatting (indentation, quotes)
Unknown metric: xyzPolicy references non-existent metricUse list_presets to see available metrics
Invalid operator: xyzPolicy uses unsupported operatorUse ==, !=, <, <=, >, >=
  • Speed: 5-15 seconds (uses ci preset internally)
  • Caching: Does not use cache (always fresh evaluation)
  • Preset used: ci preset (includes scc, smells, layer_violations, architecture_budgeting)

Begin with loose thresholds and tighten over time:

# Phase 1: Establish baseline
policy:
invariants:
- metric: scc.max_cycle_size
op: '<='
value: 10 # Allow some cycles initially
message: 'Reduce cycle size'
# Phase 2: Tighten after refactoring
policy:
invariants:
- metric: scc.max_cycle_size
op: '<='
value: 3
message: 'Cycles must be small'
# Phase 3: Enforce zero cycles
policy:
invariants:
- metric: scc.max_cycle_size
op: '<='
value: 0
message: 'No cycles allowed'

Good:

message: 'Circular dependency detected. Run `arxo cycles` to identify modules.'

Bad:

message: 'Policy violation'

Use architecture_budgeting for incremental improvement:

policy:
invariants:
- metric: architecture_budgeting.violations
op: '=='
value: 0
message: 'Architecture budget exceeded'
Terminal window
# Evaluate policy from arxo.yaml
arxo analyze --preset ci
# Check if violations exist (exit code non-zero if violations)
arxo analyze --preset ci --fail-on-violations