Recursive Meta-Guard¶
MetaGuard monitors the guardrail's own scoring decisions for drift. In
production, recursive threshold changes should be gated so adversarial traffic
cannot steer the guard by flooding one tenant, one repeated prompt shape, or
unlabelled drift windows.
MetaGuardProductionPolicy turns the meta-guard into a guarded production
option:
- Page-Hinkley, Brier, and action-rate alarms are still reported;
- threshold adjustment is blocked when one tenant dominates the window;
- threshold adjustment is blocked when one prompt hash dominates the window;
- threshold adjustment is blocked when the labelled fraction is below the configured floor;
- blocked windows are observe-only and do not mutate the
ThresholdAdjuster.
from director_ai.core.meta_guard import (
DecisionLog,
MetaAnalyzer,
MetaGuard,
MetaGuardProductionPolicy,
ThresholdAdjuster,
ThresholdBundle,
)
guard = MetaGuard(
log=DecisionLog(),
analyzer=MetaAnalyzer(reference_mean=0.25, min_window=64),
adjuster=ThresholdAdjuster(
initial=ThresholdBundle(warn_threshold=0.35, halt_threshold=0.70),
hysteresis_strikes=2,
),
production_policy=MetaGuardProductionPolicy(
min_labelled_fraction=0.20,
max_single_tenant_fraction=0.50,
max_duplicate_prompt_fraction=0.40,
),
)
verdict = guard.record(
prompt="operator-reviewed prompt",
score=0.82,
action="halt",
ground_truth=1.0,
tenant_id="tenant-a",
)
if verdict.production.blocked:
print(verdict.production.block_reason)
Use verdict.production for audit telemetry. A blocked production decision
means drift was detected but recursive adjustment was not considered safe for
automatic application.
director_ai.core.meta_guard.guard.MetaGuard
¶
MetaGuard(*, log: DecisionLog, analyzer: MetaAnalyzer, adjuster: ThresholdAdjuster | None = None, production_policy: MetaGuardProductionPolicy | None = None, window_last_n: int = 256)
Record decisions, analyse drift, auto-adjust thresholds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log
|
DecisionLog
|
Decision store. |
required |
analyzer
|
MetaAnalyzer
|
Drift detector. |
required |
adjuster
|
ThresholdAdjuster | None
|
Threshold mover — |
None
|
production_policy
|
MetaGuardProductionPolicy | None
|
Optional production gate. When supplied, detected drift windows must pass diversity/evasion checks before the adjuster is allowed to mutate thresholds. |
None
|
window_last_n
|
int
|
How many recent decisions the analyser sees per call. Default 256 — large enough for meaningful statistics, small enough to respond to drift quickly. |
256
|
director_ai.core.meta_guard.guard.MetaGuardProductionPolicy
dataclass
¶
MetaGuardProductionPolicy(min_labelled_fraction: float = 0.2, max_single_tenant_fraction: float = 0.5, max_duplicate_prompt_fraction: float = 0.4)
Gate recursive threshold changes in production deployments.
The policy does not replace drift detection. It decides whether a detected drift window is safe enough for the recursive guard layer to adjust thresholds. Dominated windows are treated as possible evasion or traffic skew and are observe-only until operator review.
evaluate
¶
evaluate(*, window: Sequence[ScoringDecision], analysis: MetaAnalysis) -> ProductionMetaGuardDecision
Return whether the current recursive adjustment may proceed.
director_ai.core.meta_guard.guard.ProductionMetaGuardDecision
dataclass
¶
ProductionMetaGuardDecision(enabled: bool, blocked: bool = False, block_reason: str = '', window_size: int = 0, labelled_fraction: float = 0.0, single_tenant_fraction: float = 0.0, duplicate_prompt_fraction: float = 0.0, evasion_score: float = 0.0)
Production gate result for recursive guard adjustment.