{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/rateapi-dev/json-schema/rateapi-dev-person-eligibility-match-schema.json",
  "title": "PersonEligibilityMatch",
  "description": "One credit union evaluated for a person by POST /v1/eligibility/search. Held-path non-matches remain visible in the `unknown` bucket; current web-derived records never publish ineligibility.",
  "x-generated": "2026-11-22",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/rateapi-dev-openapi.json#/components/schemas/PersonEligibilityMatch",
  "type": "object",
  "required": [
    "credit_union_id",
    "name",
    "state",
    "status",
    "confidence",
    "reasons",
    "engine",
    "coverage"
  ],
  "properties": {
    "credit_union_id": {
      "type": "string",
      "description": "Canonical identifier of the matched credit union."
    },
    "name": {
      "type": "string",
      "description": "Name of the matched credit union."
    },
    "state": {
      "type": "string",
      "description": "Two-letter US state code the credit union is chartered in."
    },
    "status": {
      "type": "string",
      "enum": [
        "eligible",
        "conditionally_eligible",
        "possibly_eligible",
        "unknown"
      ],
      "description": "The bucket this entry sits in. `ineligible` never appears; evaluated non-matches are returned as `unknown`."
    },
    "confidence": {
      "type": "number",
      "description": "Confidence in this match, 0–1, carried from the extracted eligibility rule.",
      "minimum": 0,
      "maximum": 1
    },
    "reasons": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Deterministic sentences explaining the verdict. Never model prose."
    },
    "paths": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/EligibilityGraphPath"
      },
      "description": "Structured graph paths. Absent on legacy-annotation fallbacks."
    },
    "join_cost_usd": {
      "type": "number",
      "description": "Up-front cost of the cheapest conditional step, when published."
    },
    "join_url": {
      "type": "string",
      "format": "uri",
      "description": "Where to take the conditional step (e.g. the association's join page)."
    },
    "engine": {
      "type": "string",
      "enum": [
        "graph",
        "legacy"
      ],
      "description": "`graph` when the verdict came from published eligibility-graph rules, `legacy` when it came from the annotation fallback for a credit union with no rules yet."
    },
    "publication": {
      "$ref": "#/$defs/EligibilityPublicationRef"
    },
    "unknown_reason": {
      "type": "string",
      "enum": [
        "no_rules",
        "geo_inputs_missing",
        "org_inputs_missing",
        "inputs_missing",
        "low_confidence_rules",
        "incomplete_fom",
        "fom_completeness_unaffirmed",
        "unmodeled_condition"
      ],
      "description": "WHY this entry is not a positive match. Present only on non-positive statuses. This is what makes a flat `unknown` array actionable: `geo_inputs_missing` / `org_inputs_missing` / `inputs_missing` mean the CALLER can resolve it by supplying one more fact; `no_rules` means we hold nothing for this institution; `incomplete_fom`, `fom_completeness_unaffirmed`, `low_confidence_rules` and `unmodeled_condition` mean we hold rules but will not turn a failure against them into a no. Legacy-annotation entries (`engine: \"legacy\"`) report their own reason mapped onto this same vocabulary."
    },
    "coverage": {
      "type": "object",
      "description": "What we HOLD about this institution, as distinct from what we concluded about the person. `status` answers \"what did we decide\"; this answers \"what were we deciding from\".",
      "required": [
        "state",
        "rules_held",
        "last_confirmed_at",
        "fom_affirmed"
      ],
      "properties": {
        "state": {
          "type": "string",
          "enum": [
            "published",
            "no_rules_held",
            "under_review"
          ],
          "description": "`published` — we hold live rules and evaluated them. `no_rules_held` — we hold none, so this answer rests on the legacy annotation. `under_review` — we hold none and the institution is queued for a human look. Deliberately coarse: our internal pipeline states are not part of this contract."
        },
        "rules_held": {
          "type": "integer",
          "minimum": 0,
          "description": "Live rules actually held and evaluated for this institution in this response. This count is coverage telemetry, not proof that every possible membership path is known."
        },
        "last_confirmed_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time",
          "description": "Most recent confirmation across those rules. Null when nothing was held, and null when the rules carry no confirmation timestamp — an unconfirmed rule does not borrow the credibility of a confirmed one."
        },
        "fom_affirmed": {
          "type": [
            "boolean",
            "null"
          ],
          "description": "Reserved coverage telemetry. False for current graph rules because no typed closed-world attestation exists; null when there were no rules to assess. Geographic source agreement alone never turns this true or authorizes a negative."
        }
      }
    },
    "missing_facts": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/EligibilityMissingFact"
      },
      "description": "The question(s) to ask this person next about THIS institution, ranked fewest-facts-most-doors and capped at 3. Present only on `unknown` and `possibly_eligible` entries, and only when a question would help."
    }
  },
  "$defs": {
    "EligibilityGraphPath": {
      "type": "object",
      "description": "One membership path through the eligibility graph, and how the supplied facts scored against it.",
      "required": [
        "rule_id",
        "kind",
        "reason",
        "conditions_matched"
      ],
      "properties": {
        "rule_id": {
          "type": "integer",
          "description": "Id of the published rule this path came from."
        },
        "kind": {
          "type": "string",
          "description": "Rule family (e.g. community_geo, employer, association, military, school, worship, family)."
        },
        "reason": {
          "type": "string",
          "description": "Deterministic sentence describing the path."
        },
        "conditions_matched": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Canonical condition ids the supplied facts satisfied."
        },
        "conditions_unknown": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Condition ids left unresolved — what to supply to decide this path."
        },
        "status": {
          "type": "string",
          "enum": [
            "eligible",
            "conditionally_eligible",
            "possibly_eligible",
            "ineligible",
            "unknown"
          ],
          "description": "Set on non-positive paths so callers can explain the gap. `ineligible` is reserved for compatibility; current customer-safe projections normalize unattested path negatives to `unknown`."
        },
        "conditional_on": {
          "type": "object",
          "description": "The one further step that would make this path apply.",
          "properties": {
            "type": {
              "type": "string",
              "description": "The kind of action the borrower must take to satisfy this path.",
              "enum": [
                "join_association",
                "family_link",
                "deposit_or_donation"
              ]
            },
            "org_id": {
              "type": "string",
              "description": "Identifier of the association, employer, or organization the borrower must join or link to."
            },
            "cost_usd": {
              "type": "number",
              "description": "Up-front cost of the step, when published."
            },
            "join_url": {
              "type": "string",
              "description": "Page where the borrower can complete the joining step.",
              "format": "uri"
            }
          }
        }
      }
    },
    "EligibilityMissingFact": {
      "type": "object",
      "description": "One question to ask the person next, bound to the one institution and the one membership condition it would unlock. Emitted on `unknown` and `possibly_eligible` entries only; an already-open door needs no question. Absent (never an empty array) when no question would help — see the response-level `unanswerable`.",
      "required": [
        "cu_id",
        "condition_id",
        "kind",
        "question",
        "fact_field",
        "why",
        "resolves_reason"
      ],
      "properties": {
        "cu_id": {
          "type": "string",
          "description": "The institution this question would unlock."
        },
        "condition_id": {
          "type": "integer",
          "description": "The membership condition that evaluated unknown. Stable across calls for a given publication."
        },
        "kind": {
          "type": "string",
          "description": "The evaluator condition kind, verbatim (`geo_residence`, `employee_of`, `military_affiliation`, …), so a caller can group questions without parsing prose."
        },
        "question": {
          "type": "string",
          "description": "The question to ask the person, in the second person, answerable in one breath. Composed in code from a fixed template; never model prose."
        },
        "fact_field": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "The request field(s) an answer populates. Always at least one, and always a field this endpoint accepts — merge the answers into the same request body and call again."
        },
        "why": {
          "type": "string",
          "description": "Why we are asking, in one deterministic sentence naming the door."
        },
        "evidence_quote": {
          "type": "string",
          "description": "Verbatim from the INSTITUTION's own page, via the rule's evidence quote, truncated on a word boundary at 240 characters. Absent when the backing rule carries no quote. This is never the person's own words."
        },
        "resolves_reason": {
          "type": "string",
          "enum": [
            "no_rules",
            "geo_inputs_missing",
            "org_inputs_missing",
            "inputs_missing",
            "low_confidence_rules",
            "incomplete_fom",
            "fom_completeness_unaffirmed",
            "unmodeled_condition"
          ],
          "description": "The `unknown_reason` an answer to this question would resolve."
        }
      }
    },
    "EligibilityProposalCoverage": {
      "type": "object",
      "description": "How many model-proposed claims from the source page survived evidence verification. This is not an attestation that every real-world field-of-membership path is known.",
      "required": [
        "scope",
        "proposed_claims",
        "verified_claims",
        "published_rules",
        "withheld_claims",
        "proposal_survival",
        "withheld_reasons"
      ],
      "properties": {
        "scope": {
          "type": "string",
          "enum": [
            "source_page_model_proposals"
          ],
          "description": "Metric scope, explicitly limited to model proposals extracted from reviewed source pages."
        },
        "proposed_claims": {
          "type": "integer",
          "minimum": 0,
          "description": "Claims proposed by extraction from the reviewed source pages."
        },
        "verified_claims": {
          "type": "integer",
          "minimum": 0,
          "description": "Proposed claims that passed evidence verification."
        },
        "published_rules": {
          "type": "integer",
          "minimum": 0,
          "description": "Verified graph rules published from the candidate."
        },
        "withheld_claims": {
          "type": "integer",
          "minimum": 0,
          "description": "Proposed claims withheld because verification did not pass."
        },
        "proposal_survival": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 1,
          "description": "Verified claims divided by proposed claims, or null when no claims were proposed."
        },
        "withheld_reasons": {
          "type": "object",
          "description": "Withheld claim counts grouped by machine-readable verification reason.",
          "additionalProperties": {
            "type": "integer",
            "minimum": 0
          }
        }
      }
    },
    "EligibilityPublicationRef": {
      "type": "object",
      "description": "Exact immutable active eligibility generation evaluated for this response.",
      "required": [
        "publication_id",
        "ruleset_sha256",
        "activated_at"
      ],
      "properties": {
        "publication_id": {
          "type": "integer",
          "description": "Database identifier of the active publication."
        },
        "ruleset_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "SHA-256 digest of the complete ordered rule set."
        },
        "activated_at": {
          "type": "string",
          "format": "date-time",
          "description": "When this generation became serving authority."
        },
        "proposal_coverage": {
          "$ref": "#/$defs/EligibilityProposalCoverage"
        }
      }
    }
  }
}