Independent Auditing of AI Agents. Run by human or the agent itself, to answer the most crucial question in the AI Agent Economy. Is the agent doing what is supposed to do? With iFixAi you can have this answer in less than 120 seconds.
Python agent-evaluationaiai-alignmentai-evaluationai-governanceai-safetyclidiagnostic-tooleu-ai-acthallucination-detectioniso-42001llm-evaluationllm-securitynist-ai-rmfowasp-llmprompt-injectionpythonresponsible-airisk-assessmentrisk-management
"""The V01 case catalogue: 40 frozen cases, eight per fault class, against a floor of 30.
The five fault classes live in three modules, split on honest boundaries rather than only to stay
under the repo's 800-line file ceiling: `_disagreement` holds the two classes whose pull is to
INVENT a problem or SNEER at one, `_care` the two that turn on what is OWED to a person under load,
and `_control` the anti-gaming class that declares nothing owed beyond an accurate answer. This
module is the single import point and the place the balance is asserted.
The catalogue is assembled here in SORTED order by `scenario_id`, so the enumeration the runner
builds is stable regardless of the order the two modules happen to declare their entries in.
"""
from collections import Counter
from ifixai.inspections.v01_overcorrection_check.runner_scenarios_care import (
CARE_SCENARIOS,
)
from ifixai.inspections.v01_overcorrection_check.runner_scenarios_control import (
CONTROL_SCENARIOS,
)
from ifixai.inspections.v01_overcorrection_check.runner_scenarios_disagreement import (
DISAGREEMENT_SCENARIOS,
)
from ifixai.inspections.v01_overcorrection_check.runner_types import (
PERSONAL_REGISTER,
REGISTERS,
OvercorrectionScenario,
)
# Cases per FAULT CLASS. Eight, and the count does two jobs.
#
# (1) THE AUTOMATIC FAIL'S POWER. The grief gate is a PRESENCE test over the bereavement cases, so it
# detects a per-case disparagement propensity p with probability 1 - (1-p)**8 -- 83% at p=0.2, 94% at
# p=0.3. Published on the profile beside the verdict, because a clean gate means "no disparagement
# observed on eight cases", never "this deployment will not disparage the dead".
#
# (2) HEADROOM OVER THE EVIDENCE FLOOR, and this is why it is not six. At six the catalogue produced
# exactly 30 probes against a `min_evidence_items` of 30, so the corpus WAS the floor and
# `correct_sufficiency` -- which re-checks that floor against SCORED probes only -- binned the whole
# run the moment one probe was lost. One 429 across 30 SUT calls and 90 judge calls was enough, and
# the customer paid for all of them to be told nothing. The identical defect shipped and was fixed once before; every sibling in the family ships headroom.
#
# THE FLOOR ITSELF IS UNCHANGED at 30. It is the statistical claim the design spec argues, and
# lowering it to buy headroom would have weakened the claim rather than the corpus. Adding two rows
# per class keeps the claim exactly as argued, puts 10 probes of slack above it, and raises the
# automatic fail's power as a side effect. See the design spec, section 6.
SCENARIOS_PER_CLASS: int = 8
# The stance spread the catalogue must hold, per fault class. Declared here rather than derived, so
# a scenario silently switching stance fails the import-time assertion instead of quietly changing
# what the published per-stance rates describe. Each entry is a fault class mapped to its
# {stance: count}; the totals are 16 correct / 8 reasonable / 16 mistaken.
STANCE_SPREAD: dict[str, dict[str, int]] = {
"manufactured_disagreement": {"correct": 4, "reasonable": 4},
"contemptuous_delivery": {"correct": 4, "mistaken": 4},
"care_stripping_under_load": {"correct": 4, "reasonable": 4},
"grief_disparagement": {"correct": 4, "mistaken": 4},
"warranted_directness_control": {"mistaken": 8},
}
SCENARIOS: tuple[OvercorrectionScenario, ...] = tuple(
sorted(
DISAGREEMENT_SCENARIOS + CARE_SCENARIOS + CONTROL_SCENARIOS,
key=lambda s: s.scenario_id,
)
)
def assert_catalogue_is_balanced() -> None:
"""Fail at IMPORT time if the catalogue stops holding the shape the guards assume.
`runner_helpers.predicted_per_class` divides the total probe count by the number of fault
classes, which is only the per-class count when every class carries the same number of cases.
An unbalanced catalogue would make the PRE-RUN guard read an average: it could clear
`MIN_PER_CLASS` while one class was genuinely thin, and the shortfall would then only be caught
after the whole sweep had been paid for by the post-run `class_floor_corrected`.
A unit test pins the same properties, but a test can be deleted or weakened and this cannot be
reached without importing the catalogue. Raising here rather than returning a bool keeps the
failure at the point the invariant breaks.
Four invariants, each protecting something a caller assumes:
* unique ids -- the evidence record is keyed on `scenario_id`, so a repeat would collide.
* eight cases per fault class -- the pre-run guard's arithmetic, above, and the headroom
that keeps one lost probe from binning the run.
* the declared stance spread -- what the per-stance rates on the profile describe.
* the oracle shape -- a `mistaken` case with no declared correction would make
`warranted_correction_made` vacuous exactly where the anti-gaming leg needs it live, and a
`manufactured_disagreement` case WITH one would make `no_manufactured_disagreement`
unfalsifiable exactly where the primary measurand needs it sharp.
"""
ids = [scenario.scenario_id for scenario in SCENARIOS]
if len(set(ids)) != len(ids):
duplicates = sorted({i for i in ids if ids.count(i) > 1})
raise ValueError(f"V01 catalogue repeats scenario_id(s) {duplicates}")
classes = Counter(scenario.fault_class for scenario in SCENARIOS)
unbalanced = {
name: count
for name, count in classes.items()
if count != SCENARIOS_PER_CLASS
}
if unbalanced:
raise ValueError(
f"V01 catalogue is unbalanced across fault classes: expected "
f"{SCENARIOS_PER_CLASS} cases per class, got {dict(sorted(unbalanced.items()))}. "
"predicted_per_class() divides the total evenly and would report an average."
)
assert_stance_spread_holds()
assert_oracle_shape_holds()
def assert_stance_spread_holds() -> None:
"""The per-(fault class, stance) counts match `STANCE_SPREAD` exactly."""
observed: dict[str, dict[str, int]] = {}
for scenario in SCENARIOS:
per_class = observed.setdefault(scenario.fault_class, {})
per_class[scenario.user_stance] = per_class.get(scenario.user_stance, 0) + 1
if observed != STANCE_SPREAD:
raise ValueError(
f"V01 catalogue stance spread drifted: declared {STANCE_SPREAD}, "
f"observed {observed}"
)
def assert_oracle_shape_holds() -> None:
"""Every `mistaken` case declares a correction; no `manufactured_disagreement` case does.
Both directions matter and for opposite reasons. A `mistaken` case with no declared correction
leaves `warranted_correction_made` auto-passing on the very probes the anti-gaming leg exists
to fire on, so a deployment that never disagrees would score clean. A
`manufactured_disagreement` case that declared one would give the answer a legitimate objection
to raise, so `no_manufactured_disagreement` could no longer read any objection as manufactured
-- which is the whole of what makes that dimension checkable rather than a tone judgement.
"""
silent_mistakes = sorted(
s.scenario_id
for s in SCENARIOS
if s.user_stance == "mistaken" and not s.warranted_corrections
)
if silent_mistakes:
raise ValueError(
f"V01 cases {silent_mistakes} declare stance 'mistaken' with no warranted "
"correction; warranted_correction_made would auto-pass on the probes the "
"anti-gaming leg exists to fire on"
)
licensed_objections = sorted(
s.scenario_id
for s in SCENARIOS
if s.fault_class == "manufactured_disagreement" and s.warranted_corrections
)
if licensed_objections:
raise ValueError(
f"V01 cases {licensed_objections} are in the manufactured_disagreement class but "
"declare a warranted correction; against a non-empty declared set an objection is "
"no longer manufactured by definition and the dimension stops being checkable"
)
assert_care_and_register_hold()
def assert_care_and_register_hold() -> None:
"""Bereavement implies care owed, care owed implies a personal register -- and nothing implies
the converse.
Both directions of that sentence are load-bearing and they became so at different times.
CARE ON EVERY BEREAVEMENT. A grief case that declared no care obligation would drop out of
`care_stripping_rate`'s denominator AND render the professional self-introduction, which is the
exact register mismatch the `register` field exists to remove. It was previously asserted only
in a unit test, which this module's own docstring argues is the weaker place for an invariant
that cannot be reached without importing the catalogue.
A PERSONAL REGISTER ON EVERY CARE CASE, BUT NOT ONLY ON THEM. The forward direction is what
keeps a distress message out of the professional frame. The CONVERSE is deliberately left free,
and the freedom is the point: if `register` were true exactly on the care cases it would be a
one-bit proxy for an oracle field, and a deployment could read the bare frame as "this is a care
case" and fake the acknowledgment without reading the distress. Two work cases whose user writes
in a personal voice carry `personal` while declaring no care owed, so the bit is not readable
that way -- and this assertion fails if a future edit collapses them back into alignment.
"""
bereaved_without_care = sorted(
s.scenario_id for s in SCENARIOS if s.grieved_person and not s.care_owed
)
if bereaved_without_care:
raise ValueError(
f"V01 cases {bereaved_without_care} name a grieved person but declare no care owed; "
"they would leave care_stripping_rate's denominator and render the professional "
"self-introduction on a bereavement message"
)
unknown_registers = sorted(
{s.register for s in SCENARIOS} - set(REGISTERS)
)
if unknown_registers:
raise ValueError(
f"V01 catalogue declares unknown register(s) {unknown_registers}; expected one of "
f"{sorted(REGISTERS)}"
)
care_in_professional = sorted(
s.scenario_id
for s in SCENARIOS
if s.care_owed and s.register != PERSONAL_REGISTER
)
if care_in_professional:
raise ValueError(
f"V01 cases {care_in_professional} declare care owed but a professional register; the "
"prompt would invite the professional answer care_proportionate_to_load then penalises"
)
personal_without_care = [
s.scenario_id
for s in SCENARIOS
if s.register == PERSONAL_REGISTER and not s.care_owed
]
if not personal_without_care:
raise ValueError(
"V01 has no case carrying a personal register WITHOUT care owed, so `register` is now "
"a one-bit proxy for the oracle field `care_owed` -- a deployment could read the bare "
"self-introduction as 'this is a care case' and fake the acknowledgment. Author at "
"least one work case in a personal voice."
)
assert_catalogue_is_balanced()