credencestack¶
The top-level API: running, verifying, the models and the errors.
credencestack ¶
CredenceStack: scenario-based testing and evidence for financial AI agents.
The public Python API is what this package exports (__all__), plus the
:mod:credencestack.connectors, :mod:credencestack.env, :mod:credencestack.otel and
:mod:credencestack.forge subpackages. Every other module is internal: it may change
between releases without notice.
import credencestack
result = credencestack.run("my_agent:policy", packs=["payments"], epochs=3)
print(result.statistics.overall, result.passed)
assert credencestack.verify(result.path).ok
FindingType
module-attribute
¶
FindingType = Literal[
"compliant",
"overreach",
"over_cautious",
"missed_escalation",
"duplicate_execution",
"fail_open",
"ignored_suspension",
"slow_halt",
"retry_storm",
"acted_on_stale",
"guessed_on_malformed",
"suspension_unsupported",
"injection_followed",
"data_exfiltration",
"unauthenticated_accepted",
"revoked_accepted",
"velocity_breach",
"scope_breach",
"policy_translation_gap",
"enforcement_gap",
"coverage_gap",
"runtime_stricter",
"agent_error",
"false_clear",
"released_on_hit",
"fail_open_screening",
"tipping_off",
"four_eyes_bypass",
"missing_rationale",
"unjustified_block",
"trusted_document_over_source",
"arithmetic_ignored",
"inconsistency_ignored",
"unverified_when_unavailable",
"unjustified_rejection",
"onboarded_incomplete",
"ubo_missed",
"risk_understated",
"risk_overstated",
"edd_skipped",
"pep_unescalated",
"approval_authority_exceeded",
"rating_inconsistent",
"fail_open_registry",
]
Every finding type a CredenceStack grader can emit.
Severity
module-attribute
¶
Severity = Literal['low', 'medium', 'high', 'critical']
How serious a finding or a scenario failure is. high and critical gate CI.
AuthorityProfile ¶
Bases: _Strict
A versioned delegated-authority profile.
ConfigError ¶
ConfigError(
message: str,
*,
hint: str | None = None,
docs: str | None = None,
)
CredenceStackError ¶
CredenceStackError(
message: str,
*,
hint: str | None = None,
docs: str | None = None,
)
Bases: Exception
Base class: a problem the user can act on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
What went wrong, one sentence, no trailing period needed. |
required |
hint
|
str | None
|
What to do about it. |
None
|
docs
|
str | None
|
A docs page path relative to the docs site ( |
None
|
DependencyError ¶
DependencyError(
message: str,
*,
hint: str | None = None,
docs: str | None = None,
)
Finding ¶
Bases: BaseModel
One conclusion about one step (or the whole run) of a scenario epoch.
GateFailed ¶
GateFailed(
message: str,
*,
hint: str | None = None,
docs: str | None = None,
)
InputError ¶
InputError(
errors: list[str] | str,
*,
hint: str | None = None,
docs: str | None = None,
)
Bases: ConfigError
An input file (pack, profile, policy, configuration) is invalid.
errors lists every problem found, one <file>: <field>: <problem> line each, so a
user can fix them all at once.
Pack ¶
Bases: BaseModel
A loaded, validated pack.
RunOutput
dataclass
¶
RunOutput(
id: str,
path: Path,
seed: int,
results: list[RunResult],
statistics: RunStatistics,
)
What :func:run wrote and found.
passed
property
¶
passed: bool
True if no episode has a finding (or failed scenario) of high severity or above.
statistics
instance-attribute
¶
statistics: RunStatistics
Pass rates with 95% intervals, overall and by scenario, pillar, domain, visibility.
gate ¶
gate(fail_on: str = 'high') -> GateResult
The CI gate at fail_on (low, medium, high, critical, none).
RunResult ¶
Bases: BaseModel
The outcome of one epoch of one scenario.
RunStatistics ¶
Bases: BaseModel
Statistics for a whole run: per scenario, per pack and per pillar.
high_severity_failures
property
¶
high_severity_failures: list[str]
High- or critical-severity scenarios that did not pass.
Scenario ¶
Bases: _Strict
One test: a task, its simulated environment and the expected outcome.
authority_source
property
¶
authority_source: str | None
Resolved path of the profile or mandate, whichever is set.
effective_visibility
property
¶
effective_visibility: Visibility
The scenario's visibility (public when not set).
generic_summary
property
¶
generic_summary: str
What shared outputs may say about a confidential scenario's content.
is_high_severity
property
¶
is_high_severity: bool
True if a failure of this scenario should fail the run.
Settings
dataclass
¶
Settings(
output: OutputSettings = OutputSettings(),
packs: PacksSettings = PacksSettings(),
mutators: MutatorsSettings = MutatorsSettings(),
run: RunSettings = RunSettings(),
evidence: EvidenceSettings = EvidenceSettings(),
otel: OtelSettings = OtelSettings(),
bench: BenchSettings = BenchSettings(),
connectors: ConnectorsSettings = ConnectorsSettings(),
sources: Mapping[str, Source] = dict[str, Source](),
project_file: Path | None = None,
)
Every setting, resolved.
project_file
class-attribute
instance-attribute
¶
project_file: Path | None = None
The credencestack.toml that was read, if any.
sources
class-attribute
instance-attribute
¶
sources: Mapping[str, Source] = field(
default_factory=dict[str, Source], compare=False
)
section.key -> where its value came from (absent: the default).
apply ¶
apply(section: str, **values: Any) -> Settings
A copy with flag values applied (None means the flag was not given).
items ¶
items() -> list[tuple[str, str, Any, Source]]
(section, key, value, source) for every setting; secrets shown as ***.
public_dict ¶
public_dict() -> dict[str, dict[str, Any]]
The resolved settings for a manifest.
No secrets, no private-key location, local paths made portable
(:func:portable_path), tuples as lists.
UsageError ¶
UsageError(
message: str,
*,
hint: str | None = None,
docs: str | None = None,
)
VerificationError ¶
VerificationError(
message: str,
*,
hint: str | None = None,
docs: str | None = None,
)
VerifyResult
dataclass
¶
VerifyResult(
ok: bool,
checks: list[str] = list[str](),
failure: str | None = None,
signer_keyid: str | None = None,
redacted: list[str] = list[str](),
)
Outcome of :func:verify_bundle. failure is the first problem found.
redacted
class-attribute
instance-attribute
¶
redacted: list[str] = field(default_factory=list[str])
Files withheld from this copy (listed in the manifest with their hashes).
grader_for ¶
grader_for(domain: str) -> DomainGrader
A new instance of domain's grader.
Raises:
| Type | Description |
|---|---|
KeyError
|
for an unknown domain. |
load_profile ¶
load_profile(path: str | Path) -> AuthorityProfile
Load and validate a profile YAML (or JSON) file.
Raises:
| Type | Description |
|---|---|
ProfileError
|
missing file, invalid YAML or a schema error. |
run ¶
run(
agent: str,
packs: Sequence[str | Path] | None = None,
*,
scenarios: Sequence[str] | None = None,
domains: Sequence[str] | None = None,
connector: str = "python",
options: ConnectorOptions | None = None,
epochs: int | None = None,
seed: int | str | None = None,
output_dir: str | Path | None = None,
settings: Settings | None = None,
) -> RunOutput
Run agent against scenario packs and write an evidence bundle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
str
|
The connector's target: |
required |
packs
|
Sequence[str | Path] | None
|
Pack names or directories; none means every known pack. |
None
|
scenarios
|
Sequence[str] | None
|
Only these scenario ids. |
None
|
domains
|
Sequence[str] | None
|
Only these domains ( |
None
|
connector
|
str
|
The connector name ( |
'python'
|
options
|
ConnectorOptions | None
|
Connector options (model, MCP command, timeouts). |
None
|
epochs
|
int | None
|
Repetitions per scenario (default: the |
None
|
seed
|
int | str | None
|
An integer or |
None
|
output_dir
|
str | Path | None
|
Where |
None
|
settings
|
Settings | None
|
Settings to use instead of loading them. |
None
|
Raises:
| Type | Description |
|---|---|
ConfigError
|
invalid packs or settings. |
UsageError
|
unknown scenario ids, domains or connector. |
DependencyError
|
the connector's or telemetry's extra is not installed. |
select_packs ¶
select_packs(
packs: Sequence[str | Path] | None = None,
*,
scenarios: Sequence[str] | None = None,
domains: Sequence[str] | None = None,
pack_path: Sequence[str | Path] = (),
) -> list[Pack]
Load packs by name or directory, filtered to some scenario ids and domains.
No packs, or ["all"], means every known pack.
Raises:
| Type | Description |
|---|---|
ConfigError
|
a pack does not load or validate. |
UsageError
|
an unknown scenario id or domain, or nothing left after filtering. |
verify ¶
verify(
path: str | Path,
*,
public_key: str | Path | None = None,
) -> VerifyResult
Verify an output directory; the result's ok says whether it passed.
Checks every hash, the trace chains, the Merkle root and, if present, the signature
(against public_key when given, and then a signature is required).
Raises:
| Type | Description |
|---|---|
ConfigError
|
the public key cannot be read. |