Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/changelog.d/609-item-bank-buyer-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Add buyer-facing item-bank lifecycle reports

## Added

- Added deterministic JSON and standalone accessible HTML reporting for complete governed item-bank lifecycle lineages, including current state, rubric/blueprint provenance, approved-use scope, evidence-class inventory, transition timeline, and explicit missing-evidence limitations.
- Cross-version comparability is reported only as supported when governed linking evidence is present; the report never infers comparability from a nominal score range or active lifecycle state.
- Reporting remains provenance-only: calibration, fit, DIF, information, linking, exposure, drift, and uncertainty arithmetic are referenced by exact evidence identity and are not recomputed in Python.
31 changes: 31 additions & 0 deletions docs/doctoring/item_bank_lifecycle_reporting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Governed item-bank lifecycle reporting

## Decision

`fast-mlsirm` exposes a report layer over the existing immutable item-bank lifecycle records. The report accepts a complete contiguous lineage beginning at the package-created `piloting` record and emits deterministic machine-readable JSON-compatible content or a standalone accessible HTML representation.

The report is deliberately provenance-only. It may state that calibration, item-fit, DIF, item-information, linking, exposure, drift, approval, suspension, or retirement evidence is present because the lifecycle record binds an exact evidence identifier and SHA-256 fingerprint. It does not recompute, reinterpret, or synthesize those numerical results in Python. Production calibration, fit, DIF, information, linking/equating, exposure, drift, and uncertainty arithmetic remain Rust-owned.

## Buyer-facing truth conditions

- The current lifecycle state is taken from the final record in a complete fingerprint-linked lineage; a disconnected successor cannot be rendered as an authoritative timeline.
- Approved-use scope, rubric/blueprint identity, candidate/pilot/audit fingerprints, policy criticality, evidence identities, transition reasons, and record fingerprints remain visible without embedding raw source, prompt, response, or provider content.
- Cross-version comparability is reported as `supported_by_linking_evidence` only when the governed evidence inventory contains a linking reference. Otherwise it is explicitly `not_demonstrated`; nominally equal score ranges and an `active` state are insufficient.
- Missing linking, exposure, and drift evidence are rendered as explicit limitations rather than silently omitted. A piloting-only report also states that calibration is not complete.
- The HTML representation is standalone, uses semantic headings/tables and captions, includes a skip link, escapes the caller-supplied title, and preserves a visible `:focus-visible` keyboard indicator.

## Security and privacy boundary

The report takes exact package-owned `ItemBankLifecycleRecord` values in a built-in tuple. It rejects container subclasses before iteration and rejects title subclasses before string callbacks. Report payloads contain governed metadata and fingerprints only; fingerprints are provenance identifiers, not authorization, anonymization, or signatures. Downstream persistence, tenant authorization, retention, encryption, export/deletion, and audit policy remain owned by the downstream application such as Psychometrics Commons.

## Research and standards basis

The lifecycle report follows evidence-centered assessment design by keeping claims connected to explicit evidence rather than treating generated content as measurement truth. Automatic item generation research also motivates retaining item-model/bank provenance instead of treating generated items as interchangeable. The current published *Standards for Educational and Psychological Testing* remains the 2014 joint AERA/APA/NCME edition while a revision process is underway; this implementation therefore cites the final 2014 standard rather than a draft revision.

## References

American Educational Research Association, American Psychological Association, & National Council on Measurement in Education. (2014). *Standards for educational and psychological testing*. American Educational Research Association. https://www.testingstandards.net/open-access-files.html

Gierl, M. J., & Lai, H. (2012). The role of item models in automatic item generation. *International Journal of Testing, 12*(3), 273–298. https://doi.org/10.1080/15305058.2011.635830

Mislevy, R. J., Almond, R. G., & Lukas, J. F. (2003). *A brief introduction to evidence-centered design* (Research Report RR-03-16). Educational Testing Service. https://doi.org/10.1002/j.2333-8504.2003.tb01908.x
316 changes: 316 additions & 0 deletions python/fast_mlsirm/rubric/item_bank_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
"""Machine-readable and accessible reports for governed item-bank lifecycles.

The report layer summarizes immutable lifecycle records and evidence identities.
It deliberately does not calculate calibration, fit, DIF, information, linking,
exposure, drift, or uncertainty; those numerical quantities remain Rust-owned.
"""

from __future__ import annotations

from html import escape
import json
from typing import Any

from .item_bank import (
ItemBankEvidenceKind,
ItemBankLifecycleRecord,
ItemBankLifecycleState,
)

_MAX_REPORT_RECORDS = 256
_MAX_TITLE_CHARACTERS = 160
_REPORT_SCHEMA_VERSION = "fast-mlsirm-item-bank-report-v1"


class ItemBankReportError(ValueError):
"""Raised when a lifecycle cannot be represented as a trustworthy report."""


def _normalize_records(records: object) -> tuple[ItemBankLifecycleRecord, ...]:
"""Validate one complete contiguous package-owned lifecycle timeline."""
if type(records) is not tuple:
raise TypeError("records must be a built-in tuple")
if not records:
raise ItemBankReportError("records must contain at least one lifecycle record")
if len(records) > _MAX_REPORT_RECORDS:
raise ItemBankReportError(
f"records must contain at most {_MAX_REPORT_RECORDS} lifecycle records"
)
for record in records:
if type(record) is not ItemBankLifecycleRecord:
raise TypeError("records must contain exact ItemBankLifecycleRecord values")

first = records[0]
if (
first.lifecycle_state is not ItemBankLifecycleState.PILOTING
or first.previous_record_fingerprint is not None
):
raise ItemBankReportError("lifecycle report must start at piloting")

stable_identity = (
first.item_id,
first.item_version,
first.candidate_fingerprint,
first.pilot_record_fingerprint,
first.audit_report_fingerprint,
first.blueprint_id,
first.rubric_id,
first.rubric_version,
first.policy_criticality,
)
previous = first
for record in records[1:]:
current_identity = (
record.item_id,
record.item_version,
record.candidate_fingerprint,
record.pilot_record_fingerprint,
record.audit_report_fingerprint,
record.blueprint_id,
record.rubric_id,
record.rubric_version,
record.policy_criticality,
)
if current_identity != stable_identity:
raise ItemBankReportError("lifecycle identity changed across report records")
if record.previous_record_fingerprint != previous.record_fingerprint:
raise ItemBankReportError("lifecycle lineage is not contiguous")
previous = record
return records


def _present_evidence_kinds(
record: ItemBankLifecycleRecord,
) -> frozenset[ItemBankEvidenceKind]:
"""Return the evidence classes accumulated by the current lifecycle record."""
return frozenset(reference.evidence_kind for reference in record.evidence_references)


def _evidence_status(
present: frozenset[ItemBankEvidenceKind],
) -> dict[str, str]:
"""Return an explicit present/not-present status for every governed class."""
return {
kind.value: "present" if kind in present else "not_present"
for kind in ItemBankEvidenceKind
}


def _limitations(
current: ItemBankLifecycleRecord,
present: frozenset[ItemBankEvidenceKind],
) -> list[str]:
"""Return explicit non-claims implied by absent lifecycle evidence."""
limitations: list[str] = []
if current.lifecycle_state is ItemBankLifecycleState.PILOTING:
limitations.append("calibration_not_completed")
if ItemBankEvidenceKind.LINKING not in present:
limitations.append("linking_evidence_not_present")
if ItemBankEvidenceKind.EXPOSURE not in present:
limitations.append("exposure_evidence_not_present")
if ItemBankEvidenceKind.DRIFT not in present:
limitations.append("drift_evidence_not_present")
return limitations


def build_item_bank_report(
records: tuple[ItemBankLifecycleRecord, ...],
) -> dict[str, Any]:
"""Build a source-text-free report from one complete lifecycle lineage.

Parameters
----------
records:
Exact package-owned lifecycle records ordered from the initial piloting
record through the current state. The chain must be contiguous.

Returns
-------
dict
JSON-compatible lifecycle, provenance, evidence, and limitation data.
"""
normalized = _normalize_records(records)
current = normalized[-1]
present = _present_evidence_kinds(current)
comparability = (
"supported_by_linking_evidence"
if ItemBankEvidenceKind.LINKING in present
else "not_demonstrated"
)
timeline = [
{
"state": record.lifecycle_state.value,
"transition_reason_id": record.transition_reason_id,
"record_id": record.record_id,
"record_fingerprint": record.record_fingerprint,
"previous_record_fingerprint": record.previous_record_fingerprint,
"approved_use_ids": list(record.approved_use_ids),
}
for record in normalized
]
return {
"schema_version": _REPORT_SCHEMA_VERSION,
"item_id": current.item_id,
"item_version": current.item_version,
"current_state": current.lifecycle_state.value,
"policy_criticality": current.policy_criticality.value,
"blueprint_id": current.blueprint_id,
"rubric_id": current.rubric_id,
"rubric_version": current.rubric_version,
"candidate_fingerprint": current.candidate_fingerprint,
"pilot_record_fingerprint": current.pilot_record_fingerprint,
"audit_report_fingerprint": current.audit_report_fingerprint,
"current_record_id": current.record_id,
"current_record_fingerprint": current.record_fingerprint,
"approved_use_ids": list(current.approved_use_ids),
"cross_version_comparability": comparability,
"evidence_status": _evidence_status(present),
"evidence_references": [
reference.to_dict() for reference in current.evidence_references
],
"timeline": timeline,
"limitations": _limitations(current, present),
"numerical_evidence_policy": (
"report_only; numerical evidence is referenced, not recomputed"
),
}


def render_item_bank_report_json(
records: tuple[ItemBankLifecycleRecord, ...],
) -> str:
"""Render one deterministic UTF-8 JSON representation of the bank report."""
report = build_item_bank_report(records)
return json.dumps(
report,
ensure_ascii=False,
sort_keys=True,
separators=(",", ":"),
) + "\n"


def _normalize_title(title: object) -> str:
"""Validate a caller-supplied HTML title before string callbacks execute."""
if type(title) is not str:
raise TypeError("title must be a built-in str")
normalized = title.strip()
if not normalized:
raise ValueError("title must not be empty")
if len(normalized) > _MAX_TITLE_CHARACTERS:
raise ValueError(
f"title must be at most {_MAX_TITLE_CHARACTERS} characters"
)
if "\n" in normalized or "\r" in normalized:
raise ValueError("title must be a single line")
return normalized


def _table_row(label: str, value: str) -> str:
"""Render one escaped definition-list row for the report summary."""
return f"<dt>{escape(label)}</dt><dd>{escape(value)}</dd>"


def render_item_bank_report_html(
records: tuple[ItemBankLifecycleRecord, ...],
*,
title: str = "Item bank lifecycle report",
) -> str:
"""Render a standalone accessible HTML lifecycle report.

The HTML includes semantic landmarks, table captions, an explicit skip link,
and a visible keyboard-focus treatment. It contains only governed IDs,
fingerprints, state, and evidence metadata from the lifecycle records.
"""
normalized_title = _normalize_title(title)
report = build_item_bank_report(records)
escaped_title = escape(normalized_title)

summary = "".join(
(
_table_row("Item", str(report["item_id"])),
_table_row("Version", str(report["item_version"])),
_table_row("Current state", str(report["current_state"])),
_table_row("Rubric", str(report["rubric_id"])),
_table_row("Rubric version", str(report["rubric_version"])),
_table_row("Policy criticality", str(report["policy_criticality"])),
_table_row(
"Cross-version comparability",
str(report["cross_version_comparability"]),
),
)
)
Comment thread
seonghobae marked this conversation as resolved.
Resolved

evidence_rows = "".join(
"<tr><th scope=\"row\">"
+ escape(kind)
+ "</th><td>"
+ escape(status)
+ "</td></tr>"
for kind, status in report["evidence_status"].items()
)
timeline_rows = "".join(
"<tr><td>"
+ escape(str(step["state"]))
+ "</td><td>"
+ escape(str(step["transition_reason_id"]))
+ "</td><td><code>"
+ escape(str(step["record_fingerprint"]))
+ "</code></td></tr>"
for step in report["timeline"]
)
limitations = report["limitations"]
limitations_html = (
"<p>No report-layer limitations were inferred from the governed "
"evidence inventory.</p>"
if not limitations
else "<ul>"
+ "".join(f"<li>{escape(str(value))}</li>" for value in limitations)
+ "</ul>"
)

return (
"<!doctype html>\n"
'<html lang="en">\n<head>\n<meta charset="utf-8">\n'
'<meta name="viewport" content="width=device-width, initial-scale=1">\n'
f"<title>{escaped_title}</title>\n"
"<style>"
"body{font-family:system-ui,sans-serif;line-height:1.5;margin:0;}"
"main{max-width:72rem;margin:auto;padding:1.25rem;}"
".skip-link{position:absolute;left:.5rem;top:.5rem;padding:.5rem;}"
":focus-visible{outline:3px solid currentColor;outline-offset:2px;}"
"table{border-collapse:collapse;width:100%;margin-block:1rem;}"
"th,td{border:1px solid currentColor;padding:.5rem;text-align:left;}"
"dt{font-weight:700;margin-top:.5rem;}dd{margin-left:0;}"
"code{overflow-wrap:anywhere;}"
"</style>\n</head>\n<body>\n"
'<a class="skip-link" href="#main-content">Skip to report</a>\n'
'<main id="main-content">\n'
f"<h1>{escaped_title}</h1>\n"
'<section aria-labelledby="summary-heading"><h2 id="summary-heading">'
"Summary</h2><dl>"
f"{summary}</dl></section>\n"
'<section aria-labelledby="evidence-heading"><h2 id="evidence-heading">'
"Evidence</h2><table><caption>Evidence inventory</caption>"
"<thead><tr><th scope=\"col\">Evidence class</th>"
"<th scope=\"col\">Status</th></tr></thead><tbody>"
f"{evidence_rows}</tbody></table></section>\n"
'<section aria-labelledby="timeline-heading"><h2 id="timeline-heading">'
"Timeline</h2><table><caption>Lifecycle timeline</caption>"
"<thead><tr><th scope=\"col\">State</th>"
"<th scope=\"col\">Reason</th><th scope=\"col\">Record fingerprint</th>"
f"</tr></thead><tbody>{timeline_rows}</tbody></table></section>\n"
'<section aria-labelledby="limitations-heading">'
'<h2 id="limitations-heading">Limitations</h2>'
f"{limitations_html}</section>\n"
"<p>Numerical evidence is referenced by governed identity and is not "
"recomputed by this report.</p>\n"
"</main>\n</body>\n</html>\n"
)


__all__ = [
"ItemBankReportError",
"build_item_bank_report",
"render_item_bank_report_html",
"render_item_bank_report_json",
]
Loading
Loading