credencestack.evidence¶
Evidence bundles: one self-describing directory per run, with the shared manifest, results, hash-chained traces, Inspect logs, the exact profiles used, framework mappings (indicative), the evidence report (built by credencestack.reports) and, after signing, the signature. Also signing, verification, redacted export and the CI gate.
Responsibilities¶
- Write the bundle for a run (
write_bundle, behindrun_to_bundle), with a manifest that hashes every file and a Merkle root over them. - Add results by domain and a financial crime and onboarding section to the report, and copy each domain policy into the bundle (
kind: policyin the catalogue), hashed like the profiles. - Map findings to the six pillars first, then to framework references (
build_mappings), always as indicative mappings. - Rebuild the report from the bundle's own files (
refresh_report, throughcredencestack.reports.evidence), so a report can be rebuilt and checked against its data. - Export a shareable
export-<id>/copy, optionally without confidential material (export.export_bundle). - Gate CI on finding severity (
gate.evaluate_gate).
Non-goals¶
- Rendering reports: that is
credencestack.reports. - Certifying compliance. The report is test evidence about simulated scenarios.
Public API¶
Signatures and purposes are generated from the code by scripts/gen_dev_reference.py; errors come from each docstring's Raises: section or from api-notes.yaml, which also holds the hand-written effects column.
| Name | Kind | Signature | Purpose | Errors | Effects |
|---|---|---|---|---|---|
BundleError |
exception | class BundleError |
Raised when a bundle cannot be written or read. | - | - |
RunInfo |
model | RunInfo(run_id, started_at, finished_at, credencestack_version, packages, python_version, platform, git_commit, …) |
What ran, with what (the run section of results.json). |
- | data |
build_mappings |
function | build_mappings(results: Sequence[RunResult], stats: RunStatistics, scenarios: dict[str, Scenario], fmap: FrameworkMap \| None = None) -> dict[str, Any] |
mappings.json: pillars first, then every framework reference with what touched it. |
- | pure |
load_framework_map |
function | load_framework_map() -> FrameworkMap |
The packaged mapping, with every reference id checked. | - | reads the packaged mapping files |
read_manifest |
function | read_manifest(bundle: str \| Path) -> Manifest |
Load manifest.json from a bundle. |
BundleError: missing or invalid manifest. | reads manifest.json |
refresh_report |
function | refresh_report(bundle: Path, *, signer_keyid: str \| None = None, trace_url_template: str \| None = None) -> Manifest |
Re-render report.html from the bundle's files and rewrite the manifest. |
- | rewrites report.html and manifest.json |
write_bundle |
function | write_bundle(out: Path, *, info: RunInfo, scenarios: Sequence[Scenario], run: Any, runtime: Mapping[str, Sequence[BaseModel]] \| None = None, reconciliation: BaseModel \| None = None, otel_ids: Mapping[str, Any] \| None = None, settings: Mapping[str, Any] \| None = None, seed_drawn: bool = False) -> Manifest |
Write the bundle for an Inspect run (run is a runner.inspect_runner.EvalRun). |
BundleError: if out holds files that are not part of this run. |
writes the bundle directory |
pipeline.run_to_bundle |
function | run_to_bundle(packs: Sequence[Pack], factory: ConnectorFactory, *, connector: str, agent: str, out: Path \| None = None, epochs: int = 1, seed: int = 0, max_samples: int = 8, judge: JudgeScorer \| None = None, runtime: dict[str, list[RuntimeDecision]] \| None = None, models: Sequence[str] \| None = None, run_id: str \| None = None, settings: Mapping[str, Any] \| None = None, seed_drawn: bool = False, on_episode: Callable[[str, int], None] \| None = None) -> BundleRun |
Run packs with agents from factory and write the bundle to out. |
BundleError: if out is not empty. |
runs every episode through Inspect; writes the bundle (and the zip) |
export.export_bundle |
function | export_bundle(bundle: Path, dest: Path, *, redact: bool = False) -> ExportResult |
Copy bundle into dest/bundle/ (dest is a new export-<id> directory). |
BundleError: the source does not verify, or dest is not empty. |
reads the bundle; writes the export zip |
gate.evaluate_gate |
function | evaluate_gate(bundle: str \| Path, threshold: str = 'high') -> GateResult |
Apply the gate to an output directory. | GateError: the results cannot be read. | reads results.json |
merkle.merkle_root |
function | merkle_root(files: Iterable[tuple[str, str]]) -> str |
Hex Merkle root over (path, sha256) pairs (sorted by path here). |
- | pure |
signing.generate_keypair |
function | generate_keypair(out_dir: str \| Path, *, overwrite: bool = False) -> tuple[Path, Path] |
Write a new Ed25519 keypair into out_dir. |
KeyFileError: if out_dir is inside a git working tree (keys must never be committed), is not a directory, or already holds a key (without overwrite). |
writes signing.key (mode 0600) and signing.pub |
signing.load_private_key |
function | load_private_key(path: str \| Path) -> Ed25519PrivateKey |
Load a PEM Ed25519 private key. | KeyFileError: missing file or not an Ed25519 private key. | reads the key file |
signing.load_public_key |
function | load_public_key(path: str \| Path) -> Ed25519PublicKey |
Load an Ed25519 public key: PEM, or base64 of the raw 32 bytes. | KeyFileError: missing file or not an Ed25519 public key. | reads the key file (or parses base64) |
signing.sign_statement |
function | sign_statement(key: Ed25519PrivateKey, manifest_bytes: bytes, merkle_root: str, output_id: str) -> dict[str, Any] |
Return the signature.json document for a manifest. |
- | reads the wall clock (signed_at) |
verify.verify_bundle |
function | verify_bundle(bundle: str \| Path, *, public_key: Ed25519PublicKey \| None = None, require_signature: bool = True) -> VerifyResult |
Check file hashes, trace hash chains, the Merkle root and the Ed25519 signature. | - | reads the bundle (or the zip); returns the first failure instead of raising |
Examples¶
Bundle builder: results to manifest¶
Two scenarios, two epochs each, with the scripted safe agent.
examples/dev/bundle_builder.py
"""Bundle builder: run results -> bundle files and manifest.json."""
from __future__ import annotations
import json
import tempfile
from pathlib import Path
from credencestack.agents import scripted_safe
from credencestack.connectors import PythonConnector
from credencestack.evidence.pipeline import run_to_bundle
from credencestack.packs import load_pack
from examples.dev._common import show
pack = load_pack("payments")
pack.scenarios = [s for s in pack.scenarios if s.id in ("PAY-001", "PAY-002")]
with tempfile.TemporaryDirectory() as tmp:
out = Path(tmp) / "bundle"
run = run_to_bundle(
[pack],
lambda: PythonConnector(scripted_safe),
connector="python",
agent="credencestack.agents:scripted_safe",
out=out,
epochs=2,
seed=0,
)
print("# files written")
for p in sorted(out.rglob("*")):
if p.is_file() and "inspect_logs" not in p.parts:
print(" ", p.relative_to(out).as_posix())
manifest = json.loads((out / "manifest.json").read_text())
files = manifest.pop("outputs")
show("manifest.json without its file list", manifest)
show(f"manifest.json outputs[0] of {len(files)}", files[0])
Output (generated by scripts/gen_doc_examples.py --only dev):
# files written
authority/demo_ap_agent.yaml
manifest.json
mappings.json
report.html
results.json
traces/PAY-001/0.jsonl
traces/PAY-001/1.jsonl
traces/PAY-002/0.jsonl
traces/PAY-002/1.jsonl
# manifest.json without its file list
{
"schema": "credencestack.evidence/v1",
"kind": "run",
"id": "run-<id>",
"created_at": "<time>",
"credencestack_version": "1.0.0rc4",
"settings": {},
"environment": {
"python_version": "3.12.11",
"platform": "Darwin 25.5.0 arm64",
"packages": {
"inspect-ai": "0.3.291",
"pydantic": "2.14.3",
"cryptography": "50.0.2",
"langchain": "1.5.2",
"langgraph": "1.2.22",
"langchain-core": "1.8.4"
}
},
"inputs": {
"packs": [
{
"name": "payments",
"version": "1.0.0",
"digest": "<sha256>",
"visibility": "public",
"scenarios": [
"PAY-001",
"PAY-002"
]
}
],
"profiles": [
{
"path": "authority/demo_ap_agent.yaml",
"kind": "profile",
"id": "demo-ap-profile",
"version": "1.1.0",
"sha256": "<sha256>",
"scenarios": [
"PAY-001",
"PAY-002"
]
}
],
"seed": 0,
"seed_drawn": false,
"connector": "python",
"agent": "credencestack.agents:scripted_safe",
"models": [],
"epochs": 2,
"runtime_sources": []
},
"merkle_root": "<sha256>",
"visibility": "public",
"run": {
"started_at": "<time>",
"finished_at": "<time>",
"seeds": {
"PAY-001": [
662159364,
1799514441
],
"PAY-002": [
567621678,
770990668
]
}
}
}
# manifest.json outputs[0] of 9
{
"path": "authority/demo_ap_agent.yaml",
"sha256": "<sha256>",
"bytes": 1844
}
Invariants and gotchas¶
- Confidential material goes under
confidential/. The report shows such scenarios only as ids, pillars, finding types and severity with a generic message. - Redaction keeps the manifest consistent: redacted files stay listed with their hashes and are marked
redacted: true. The Merkle root is unchanged, soevidence verifystill passes, including the signature. refresh_reportrewritesreport.htmland the manifest.--signcalls it first (to name the signer on the cover) and then signs, so sign last: any later change breaks verification.- Framework mappings are indicative and say so on every page of the report; do not word them as compliance claims.
Where the tests are¶
Test files that import this package's modules (from the file index):
tests/docs/test_sample_report.pytests/integration/test_confidential_bundles.pytests/integration/test_evidence_bundle.pytests/integration/test_github_workflows.pytests/integration/test_manifests.pytests/unit/test_bench.pytests/unit/test_canonical.pytests/unit/test_gate.pytests/unit/test_otel.pytests/unit/test_otel_workflows.pytests/unit/test_reports.pytests/unit/test_verify.py