canopy-rules API Reference
Overview
Cross-link: canopy-rules Data Model (#419)
Manages JDM (JSON Decision Model) rulesets used by all program services for eligibility logic (ADR-003). Rulesets are loaded from disk on startup (not created over HTTP); the API provides read access to the loaded rulesets plus a generic evaluation endpoint that any service can call.
- Base URL
-
container port 8001 (host:
CANOPY_PORT_CANOPY_RULES_8001in.ports.env); every route below is mounted under/v1 - Authentication
-
Bearer token: a canopy-identity token for this receiver (its
audisurn:canopy:service:canopy-rules), authenticated by the service’s identity receiver (ADR-049 Amendment 14): no bearer is 401token_missing, a token it refuses 401token_rejected, anX-Canopy-Actorheader 400actor_header_retired, and no trustworthy key set in time 503keys_unavailable. - Access
-
canopy-caps, canopy-eligibility, canopy-medicaid, canopy-snap, canopy-tanf and canopy-wic hold a system edge to canopy-rules; canopy-cli holds a delegation edge (
canopy rules, canopy CLI Reference). Every route admits a system caller; the ruleset reads andPOST /v1/evaluatealso admit a caseworker+ worker through canopy-cli, andGET /v1/evaluationsandGET /v1/corpusare system-only. A refusal is 403 with itsReceiverDenialcode (ADR-049 Amendment 14); each route’s constant is in the authorization inventory. - Swagger UI
-
/swagger-uion the same host port - Database
-
canopy_rules
Endpoints
GET /v1/rule-sets
List the rulesets known to the loader, with pagination and search.
- Access
-
system; caseworker+ via canopy-cli (
delegated::RULES_GET_RULE_SETS)
Query parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
|
integer |
200 (max 500) |
Page size |
|
integer |
0 |
Offset for pagination |
|
string |
— |
Filter by ruleset name (substring match) |
Response (200): Array of RuleSetSummary (logical ruleset names only).
[
{ "name": "snap-eligibility" },
{ "name": "georgia-snap-deductions" }
]
GET /v1/rule-sets/{name}
Get a single ruleset’s JDM document by its logical name. Reads the backing JDM file from disk.
- Access
-
system; caseworker+ via canopy-cli (
delegated::RULES_GET_RULE_SETS_NAME)
Path parameters: name — logical ruleset name (the name field inside the JDM file).
Response (200): Raw JDM document (nodes/edges object) for the ruleset.
Response (404): Rule set not found.
POST /v1/evaluate
Evaluate a ruleset against input data. This is the primary endpoint called by program services during eligibility determination.
- Access
-
system; caseworker+ via canopy-cli (
delegated::RULES_POST_EVALUATE)
Query parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
|
boolean |
false |
When |
|
string |
— |
#680: pin the evaluation to a stored corpus version for replay. Omitted (or equal to the live corpus hash) evaluates the live corpus; a stored non-live hash replays that exact ruleset version from |
|
boolean |
true |
#680: when |
Request: EvaluateRequest
{
"rule_set_name": "snap-eligibility",
"context_type": "household",
"context_id": "uuid-of-household",
"input": {
"gross_monthly_income": 1500,
"household_size": 3,
"has_elderly_disabled": false
}
}
Response (200): EvaluateResponse — structured output from the ruleset’s output node, the wall-clock duration_ms, and (when trace=true) a node-by-node trace plus derivation_edges: a typed list of RuleFirings (the per-node rule_ref + namespaced input fields + declared outputs with their values), folded from the trace joined to the parsed ruleset graph. The program services rewrite these into the determination snapshot’s derivation_graph (#679, ADR-028 Amendment 2). Both fields are null when trace was not requested.
Numbers in output and trace keep their fractions (#2926). An integral value is a JSON integer, and a fractional one is a JSON number at f64 precision (about 15 significant digits, so every cent figure exactly). A rule that computes 412.38 answers 412.38. This is zen-engine’s own serialization since 2.0; under 0.55, which truncated every fractional number to a whole one, canopy-rules wrote the numbers itself to the same result.
{
"output": { "eligible": true, "allotment": 535 },
"duration_ms": 4,
"trace": null,
"derivation_edges": null
}
Response (404): Rule set not found.
GET /v1/evaluations
List recent evaluations (audit trail).
- Access
-
system (inline
Admission::system()); a user is 403system_caller_required
Query parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
|
integer |
50 (max 200) |
Page size |
|
integer |
0 |
Offset for pagination |
|
string |
— |
Filter by ruleset name (substring match) |
Response (200): Array of RuleEvaluation objects (id, ruleset name, input, output, duration_ms, created_at, optional context type/id).
GET /v1/corpus
The live ruleset-corpus content hash (#1469; ADR-002 Amendment 1). A bulk
cohort run resolves this once at enact time as the corpus half of its pinned
policy target; the value equals the corpus_hash every unpinned
POST /v1/evaluate response echoes, and is persisted in
ruleset_corpus_versions at boot so a later pinned replay always resolves.
- Access
-
system (inline
Admission::system()); a user is 403system_caller_required
Response (200): CorpusInfo — { "corpus_hash": "<hex sha-256>" }.
Error Codes
| Code | Meaning |
|---|---|
401 |
No bearer ( |
403 |
The route’s admission refuses the caller: |
404 |
Ruleset not found ( |
422 |
|
500 |
Internal error reading/parsing a JDM file or evaluating a ruleset. An evaluation whose output or trace does not serialize to JSON is one of these, never a 200 with a |
503 |
|
Notes
-
Rulesets are loaded at startup from the configuration layers
CANOPY_CONFIG_SOURCEnames (NamedFilesystemLoader::from_snapshotinservices/canopy-rules/src/engine.rs; Configuration Reference › Configuration source): every layer’s top-level*.jsonJDM file, lowest layer first. A higher layer’s decision replaces a lower layer’s of the same embeddednameonly when the higher layer’s manifest lists that name underoverrides; an undeclared collision, or two files of one layer carrying one name, refuses the start, naming both files (#3372; declared overrides).rulesets_dirandfederal_rulesets_dirare retired -
Evaluations run on a pool of pinned worker threads (
tokio_util::task::LocalPoolHandle,engine.rs) because zen-engine futures are!Send; the pool size iseval_workers(CANOPY_RULES__EVAL_WORKERS;0= auto,clamp(2..=16)ofavailable_parallelism) -
Audited evaluations (the
audit=truedefault) record arule_evaluationsrow + arules.evaluatedevent, written best-effort off the request path since #1296 — soGET /v1/evaluationsis eventually consistent, and the telemetry write can never exhaust the pool or fail an evaluation. This is internal service telemetry, not the compliance audit-of-record (ADR-019: auditors read canopy-eligibility per-case views) -
See ADR-003 for the design rationale