evaluate_policy
evaluate_policy
Section titled “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.
Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
project_path | string | Yes | Absolute or relative path to the project root directory |
policy_yaml | string | No | Inline policy YAML content (optional — uses arxo.yaml if not provided) |
Response
Section titled “Response”Returns a JSON summary with policy violations and current metric values.
Response Schema
Section titled “Response Schema”{ "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 } } ] } ]}Policy YAML Format
Section titled “Policy YAML Format”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'Supported Operators
Section titled “Supported Operators”| Operator | Description |
|---|---|
== | Equal to |
!= | Not equal to |
< | Less than |
<= | Less than or equal to |
> | Greater than |
>= | Greater than or equal to |
Examples
Section titled “Examples”No violations (passing policy)
Section titled “No violations (passing policy)”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 } } ] } ]}Violations detected
Section titled “Violations detected”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 } } ] } ]}Inline policy (no config file)
Section titled “Inline policy (no config file)”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 } } ] } ]}Common Policies
Section titled “Common Policies”Zero circular dependencies
Section titled “Zero circular dependencies”policy: invariants: - metric: scc.max_cycle_size op: '<=' value: 0 message: 'No circular dependencies allowed'Propagation cost ceiling
Section titled “Propagation cost ceiling”policy: invariants: - metric: propagation_cost.system.ratio op: '<=' value: 0.15 message: 'System propagation cost must not exceed 15%'No architectural smells
Section titled “No architectural smells”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'Layer violation enforcement
Section titled “Layer violation enforcement”policy: invariants: - metric: layer_violations.violations_count op: '==' value: 0 message: 'No layer violations allowed'Security policy
Section titled “Security policy”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'Workflow
Section titled “Workflow”Use this tool in a CI/CD pipeline:
1. evaluate_policy → check for violations2. If violations_count > 0: a. Fail the build b. Comment on PR with violations c. Link to get_hotspots or suggest_refactors for guidance3. Else: proceed with mergeSee Workflows: Policy enforcement for a full example.
Error Cases
Section titled “Error Cases”| Error | Cause | Solution |
|---|---|---|
missing required parameter: project_path | project_path not provided | Include project_path in request |
Failed to parse policy YAML | Invalid YAML syntax | Check YAML formatting (indentation, quotes) |
Unknown metric: xyz | Policy references non-existent metric | Use list_presets to see available metrics |
Invalid operator: xyz | Policy uses unsupported operator | Use ==, !=, <, <=, >, >= |
Performance
Section titled “Performance”- Speed: 5-15 seconds (uses
cipreset internally) - Caching: Does not use cache (always fresh evaluation)
- Preset used:
cipreset (includesscc,smells,layer_violations,architecture_budgeting)
Best Practices
Section titled “Best Practices”Start with lenient policies
Section titled “Start with lenient policies”Begin with loose thresholds and tighten over time:
# Phase 1: Establish baselinepolicy: invariants: - metric: scc.max_cycle_size op: '<=' value: 10 # Allow some cycles initially message: 'Reduce cycle size'
# Phase 2: Tighten after refactoringpolicy: invariants: - metric: scc.max_cycle_size op: '<=' value: 3 message: 'Cycles must be small'
# Phase 3: Enforce zero cyclespolicy: invariants: - metric: scc.max_cycle_size op: '<=' value: 0 message: 'No cycles allowed'Use clear, actionable messages
Section titled “Use clear, actionable messages”Good:
message: 'Circular dependency detected. Run `arxo cycles` to identify modules.'Bad:
message: 'Policy violation'Combine with architectural budgets
Section titled “Combine with architectural budgets”Use architecture_budgeting for incremental improvement:
policy: invariants: - metric: architecture_budgeting.violations op: '==' value: 0 message: 'Architecture budget exceeded'Related Tools
Section titled “Related Tools”analyze_architecture— Run full analysis with policies in configget_hotspots— Find modules causing violationscheck_cycles— Fast cycle check for SCC policies
Related Resources
Section titled “Related Resources”policy://violations/<path>— Read cached policy violations
Related Guides
Section titled “Related Guides”- Policy Examples — Sample policies for common scenarios
- CI Integration — Using policies in CI/CD
CLI Equivalent
Section titled “CLI Equivalent”# Evaluate policy from arxo.yamlarxo analyze --preset ci
# Check if violations exist (exit code non-zero if violations)arxo analyze --preset ci --fail-on-violations