src.dackar.RCA.synthesis.rca_synthesizer_v31

Attributes

JsonDict

Classes

LLMClient

Minimal structured-generation interface expected by the synthesizer.

RCASynthesizerConfig

Tunable configuration for RuleValidatedRCASynthesizerV31.

RuleValidatedRCASynthesizerV31

Synthesizer aligned to richer TSKR-aware causality candidate structure.

Functions

utcnow_iso()

Module Contents

src.dackar.RCA.synthesis.rca_synthesizer_v31.JsonDict[source]
src.dackar.RCA.synthesis.rca_synthesizer_v31.utcnow_iso()[source]
Return type:

str

class src.dackar.RCA.synthesis.rca_synthesizer_v31.LLMClient[source]

Bases: Protocol

Minimal structured-generation interface expected by the synthesizer.

generate_json(model, prompt, temperature=0.1)[source]

Generate a JSON object from a prompt.

Parameters:
  • model (str) – Model identifier to invoke.

  • prompt (str) – Fully-rendered prompt string.

  • temperature (float) – Sampling temperature; the synthesizer passes a low default for determinism.

Returns:

The parsed JSON object emitted by the model. Implementations must return a dict (already JSON-decoded), not a raw string. A generation or decode failure should raise; the synthesizer catches the exception and falls back to deterministic template synthesis.

Return type:

JsonDict

class src.dackar.RCA.synthesis.rca_synthesizer_v31.RCASynthesizerConfig[source]

Tunable configuration for RuleValidatedRCASynthesizerV31.

llm_model[source]

Model identifier passed to LLMClient.generate_json.

llm_prompt_version[source]

Prompt template version stamped into card provenance.

temperature[source]

Sampling temperature for LLM synthesis.

max_candidates_in_prompt[source]

Maximum causality candidates rendered into the synthesis prompt.

max_synthesis_extra_review_candidates[source]

Additional lower-ranked candidates retained for review context beyond the prompt cap.

max_evidence_in_prompt[source]

Maximum evidence snippets rendered into the prompt.

min_evidence_per_candidate_in_prompt[source]

Minimum evidence snippets guaranteed per candidate when available.

allow_fallback_template_fill[source]

When True, a failed or invalid LLM generation falls back to deterministic template synthesis instead of raising.

minimum_primary_score[source]

Baseline composite-score floor the primary hypothesis must clear to pass the minimum-evidence gate. Event severity may raise this floor (see minimum_score_for_severity) but never lowers it.

llm_model: str = 'llama3:8b'[source]
llm_prompt_version: str = 'rca_synth_v3_1'[source]
temperature: float = 0.1[source]
max_candidates_in_prompt: int = 5[source]
max_synthesis_extra_review_candidates: int = 8[source]
max_evidence_in_prompt: int = 10[source]
min_evidence_per_candidate_in_prompt: int = 1[source]
allow_fallback_template_fill: bool = True[source]
minimum_primary_score: float = 0.35[source]
class src.dackar.RCA.synthesis.rca_synthesizer_v31.RuleValidatedRCASynthesizerV31(llm_client, config=None)[source]

Synthesizer aligned to richer TSKR-aware causality candidate structure.

Responsibilities:
  • select top candidates and evidence

  • build a constrained prompt

  • call LLM for structured JSON generation

  • normalize output into rca_card schema

  • validate minimum semantic requirements

  • fallback to deterministic template synthesis if needed

Parameters:
_PROXIMATE_CATEGORIES[source]
_CONTRIBUTING_CATEGORIES[source]
_ROOT_CATEGORIES[source]
_CHAIN_POSITION_PRIMARY_TIE_MARGIN = 0.05[source]
llm_client[source]
config[source]
synthesize(event, telemetry_summary, kg_context, tskr_patterns, causality_candidates, evidence_bundle, operational_context, pm_compliance, ishikawa_matrix, run_context, cmms_context=None, similar_event_list=None)[source]

Synthesize a validated RCA card from structured reasoning artifacts.

Parameters:
  • event (JsonDict) – Target abnormal event. Must carry event_id (or id); an optional severity (1–5) raises the minimum-evidence gate floor.

  • telemetry_summary (JsonDict) – Telemetry anomaly summary for the event window.

  • kg_context (JsonDict) – Knowledge-graph neighbourhood (components, failure modes, barriers).

  • tskr_patterns (Optional[JsonDict]) – TSKR chain-position patterns, or None when unavailable.

  • causality_candidates (JsonDict) – Ranked candidate hypotheses under candidates (each with scores, evidence posture, and optional epistemics digest).

  • evidence_bundle (JsonDict) – Retrieved evidence snippets keyed for citation.

  • operational_context (Optional[JsonDict]) – Optional supporting artifacts folded into the card when present.

  • pm_compliance (Optional[JsonDict]) – Optional supporting artifacts folded into the card when present.

  • ishikawa_matrix (Optional[JsonDict]) – Optional supporting artifacts folded into the card when present.

  • cmms_context (Optional[JsonDict]) – Optional supporting artifacts folded into the card when present.

  • similar_event_list (Optional[JsonDict]) – Optional supporting artifacts folded into the card when present.

  • run_context (JsonDict) – Orchestrator run context (run_id, optional event_id / asset_id).

Returns:

An RCA card conforming to schemas/rca_card.json. On LLM failure or invalid output a deterministic fallback card is returned instead (validation_status.fallback_used = True) rather than raising. validation_status records schema/citation/evidence-gate outcomes and synthesis_quality (deterministic | partial_llm | full_llm).

Return type:

JsonDict

_HARD_GATE_ORDER = ('physical_plausibility', 'timeline_consistency', 'barrier_logic')[source]
static _eliminating_gates_for(candidate)[source]

Gate(s)/posture(s) that removed a candidate from primary standing.

Parameters:

candidate (JsonDict)

Return type:

List[str]

_build_gate_disposition(*, card, causality_candidates)[source]

F-4 — make the elimination-first semantics explicit and auditable.

Hard gates already run (after scoring) and set primary_eligibility="blocked", ruleout, and primary_block_reasons on candidates — the raw audit exists but is scattered, and an eliminated candidate keeps its (possibly high) composite_score. This consolidates the verdicts into one card block stating that a failed gate is dispositive regardless of score, and surfaces any high-scoring candidate that a gate eliminated so it cannot be silently outranked-then-ignored. Purely additive; no pipeline reordering, no ranking change.

Parameters:
Return type:

JsonDict

_build_causal_graph(*, card, event, causality_candidates)[source]

N-6 — assemble one inspectable, directed per-run causal graph.

Causal reasoning is otherwise spread across TSKR chain-position, the telemetry signal-DAG, common-cause/explain-away links, near-tie competition, and hard gates, so depth/direction/mechanism are each approximated separately and never fall out of a single model the analyst can contest. This consolidates those already-computed signals into one graph: nodes are the target event and the assessed candidates; directed edges commit a cause->effect ordering where the signals support it (chain_position vs the event, shared-cause explain-away), and undirected edges mark near-tie competition. Purely additive and ranking-neutral — it reflects the existing scores, making N-1/N-2/N-3 checkable by construction.

Parameters:
Return type:

JsonDict

static _build_score_interpretation()[source]

N-4 — honest semantics for composite_score.

The composite is a weighted blend of heuristic sub-scores with hand-set weights and relation priors; it is not calibrated against outcome frequencies, and any score confidence interval encodes data availability, not statistical uncertainty. Emitting this block prevents composite_score = 0.72 from being read as ‘72% likely the cause’. Constant, additive, and ranking-neutral.

Return type:

JsonDict

_select_candidates(causality_candidates)[source]

Top-N by score plus any review_required rows (SE review §6.7 H1 / NH11).

Parameters:

causality_candidates (JsonDict)

Return type:

List[JsonDict]

static _chain_position_of(candidate)[source]
Parameters:

candidate (JsonDict)

Return type:

str

_promote_initiator_over_consequence(ranked)[source]

Promote a near-tie initiating candidate ahead of a top consequence.

Conservative: only fires when the #1 candidate is a consequence and some initiating candidate scores within _CHAIN_POSITION_PRIMARY_TIE_MARGIN of it. A clearly-stronger consequence is left in place (and later flagged for analyst review by _apply_chain_position_review_flag).

Parameters:

ranked (List[JsonDict])

Return type:

List[JsonDict]

_apply_chain_position_review_flag(card, causality_candidates)[source]

WS2 Part A: flag when the primary hypothesis is a downstream consequence.

A consequence is a derivative effect, not the initiating cause. When the primary chain_position is consequence, surface an analyst attention flag and an uncertainty note pointing to the strongest upstream initiating candidate, so the analyst reviews whether the true primary cause is upstream. Depth labelling is intentionally left category-based (WS2 scope = Part A only).

Parameters:
Return type:

None

_apply_temporal_support_flag(card, causality_candidates)[source]

N-2: flag when the primary hypothesis’s temporal support is unestablished.

When no TSKR pattern matched the primary failure mode, its temporal sub-score is a co-occurrence proxy (anomalies merely co-present in the event window) — not established temporal precedence and not a propagation path. Surface this so an engineer does not read a proxy-derived temporal score as confirmed temporal causation (post-hoc/cum-hoc guard).

Parameters:
Return type:

None

_apply_signal_dag_position_flag(card, causality_candidates)[source]

P-5: surface the telemetry signal-DAG causal position of the primary hypothesis.

The signal-evidence builder classifies each candidate’s anomaly within the telemetry-propagation DAG (root / common-cause root / intermediate / convergence confluence) and records whether a root’s onset lead over its successor was actually established. That view was previously consumed only to zero convergence evidence. Here it is surfaced to the analyst in two honest, additive ways (no ranking or confidence change):

  • the primary sits at a convergence confluence — a downstream node where multiple propagation chains meet, i.e. a likely symptom rather than the initiator; or

  • the primary is a signal-DAG initiator whose onset lead was not established (co-temporal / OVERLAPS), so telemetry does not demonstrate it precedes the sequence it is claimed to initiate.

Parameters:
Return type:

None

_apply_common_cause_explain_away_flag(card, causality_candidates)[source]

N-3: flag when the primary hypothesis is a co-symptom of a suspected common cause.

The engine’s common-cause analysis identifies when several candidates converge on a shared dependency (common_cause_summary.suspected_common_cause), names the strongest shared-cause candidate (top_common_cause_candidate_id) and lists the remaining co-symptoms (explained_away_candidate_ids). A downstream symptom of a common cause is not itself the initiating root — if such a co-symptom is selected primary, surface an analyst flag pointing at the shared cause / shared dependency so the true common cause is reviewed. Additive (flag + uncertainty note); ranking is unchanged.

Parameters:
Return type:

None

_apply_data_limited_confidence_cap(card, causality_candidates)[source]

P-7: cap card confidence when the primary hypothesis is data-limited.

The engine already reduces a data-limited candidate’s quality multiplier and flags data_limited_conclusion with critical_streams_below_floor, but that was previously only annotated (uncertainties/evidence-gaps) — the confidence label could still read high. §3.5/§7 require conservative bias under sparse data, so a data-limited primary must not carry a high confidence claim. Cap the primary and executive confidence at medium (downward-only; never raises) and add an analyst attention flag. Ranking is untouched.

Parameters:
Return type:

None

_select_evidence(evidence_bundle, selected_candidates=None)[source]
Parameters:
Return type:

List[JsonDict]

static _evidence_row_key(row)[source]
Parameters:

row (JsonDict)

Return type:

str

static _evidence_linked_candidate_id(row)[source]
Parameters:

row (JsonDict)

Return type:

Optional[str]

static _authority_level_rank(authority_level)[source]
Parameters:

authority_level (Any)

Return type:

int

_build_prompt(event, telemetry_summary, kg_context, tskr_patterns, causality_candidates, evidence_bundle, operational_context, pm_compliance, ishikawa_matrix, run_context, cmms_context=None)[source]
Parameters:
Return type:

str

_compact_cmms_context(cmms_context)[source]

Return a token-efficient summary of cmms_context for the prompt.

Only the most recent CR/WO records (up to 5 each) are included, with long_text stripped (long_text is already in Chroma for semantic retrieval — duplicating it in the prompt wastes tokens). The recurrence_summary and lookback window are always included.

Parameters:

cmms_context (Optional[JsonDict])

Return type:

Optional[JsonDict]

_normalize_llm_output(raw_output, rca_id, event, evidence_bundle, run_context, causality_candidates)[source]
Parameters:
Return type:

JsonDict

_inject_review_required_questions(analyst_review, *, causality_candidates, max_candidates=3)[source]

Ensure Stage F review_required candidates are visible to analysts in analyst_review.questions_to_resolve.

Parameters:
  • analyst_review (Any)

  • causality_candidates (JsonDict)

  • max_candidates (int)

Return type:

JsonDict

_infer_evidence_support_role(evidence_row, primary_candidate)[source]
Parameters:
Return type:

str

_infer_linked_candidate_id(evidence_row, primary_candidate)[source]
Parameters:
Return type:

Optional[str]

_build_alternative_supports(alt)[source]
Parameters:

alt (JsonDict)

Return type:

List[str]

_build_alternative_weaknesses(alt, primary_candidate)[source]
Parameters:
Return type:

List[str]

_build_alternative_citations(alt, primary_candidate)[source]
Parameters:
Return type:

List[JsonDict]

_normalize_alternatives(alternatives, primary_candidate)[source]
Parameters:
Return type:

List[JsonDict]

_normalize_contributing_causes(causes, primary_candidate)[source]
Parameters:
Return type:

List[JsonDict]

_normalize_evidence_rows(evidence_rows, primary_candidate, excerpt_index=None)[source]
Parameters:
Return type:

List[JsonDict]

static _build_evidence_excerpt_index(evidence_rows)[source]

Build a lookup index so card evidence rows can recover raw snippet excerpts.

Parameters:

evidence_rows (List[JsonDict])

Return type:

JsonDict

static _looks_like_placeholder_excerpt(text)[source]
Parameters:

text (str)

Return type:

bool

_resolve_evidence_excerpt(*, row, excerpt_index)[source]

Ensure evidence excerpt is source text when available.

Parameters:
Return type:

str

_POSTURE_WARNINGS: Dict[str, str][source]
_SEVERITY_SCORE_FLOORS: Dict[int, float][source]
static minimum_score_for_severity(severity)[source]

Return the minimum composite score a primary must clear for a severity.

Parameters:

severity – Event severity 1 (minor) … 5 (critical). Accepts int or numeric string; None or an unparseable value defaults to severity 3.

Returns:

The severity floor from _SEVERITY_SCORE_FLOORS (0.35 for any severity outside 1–5). Callers combine this with config.minimum_primary_score via max so the floor only ever tightens the gate.

Return type:

float

_CRITICAL_SAFETY_KEYWORDS = ('reactor protection', 'reactor trip', 'trip logic', 'reactor shutdown', 'containment...[source]
_HIGH_SAFETY_KEYWORDS = ('core cooling', 'emergency core cooling', 'emergency cooling', 'residual heat removal', 'decay...[source]
Parameters:
Return type:

List[JsonDict]

Parameters:
Return type:

None

static _priority_rank(priority)[source]
Parameters:

priority (str)

Return type:

int

classmethod _max_priority(a, b)[source]
Parameters:
  • a (str)

  • b (str)

Return type:

str

classmethod _bump_priority(base, steps=1)[source]
Parameters:
  • base (str)

  • steps (int)

Return type:

str

static _normalize_safety_text(value)[source]
Parameters:

value (Any)

Return type:

str

classmethod _contains_any_keyword(values, keywords)[source]
Parameters:
  • values (List[str])

  • keywords (tuple)

Return type:

bool

static _candidate_safety_context(primary_candidate)[source]
Parameters:

primary_candidate (Optional[JsonDict])

Return type:

JsonDict

_candidate_barrier_context(primary_candidate)[source]
Parameters:

primary_candidate (Optional[JsonDict])

Return type:

JsonDict

static _candidate_risk_context(primary_candidate)[source]
Parameters:

primary_candidate (Optional[JsonDict])

Return type:

JsonDict

classmethod _apply_safety_priority(current_priority, safety_ctx)[source]
Parameters:
  • current_priority (str)

  • safety_ctx (JsonDict)

Return type:

str

classmethod _apply_barrier_priority(current_priority, barrier_ctx)[source]
Parameters:
  • current_priority (str)

  • barrier_ctx (JsonDict)

Return type:

str

classmethod _apply_risk_priority(current_priority, risk_ctx)[source]
Parameters:
  • current_priority (str)

  • risk_ctx (JsonDict)

Return type:

str

static _apply_barrier_rationale_weighting(action_row, barrier_ctx)[source]
Parameters:
Return type:

None

static _apply_risk_rationale_weighting(action_row, risk_ctx)[source]
Parameters:
Return type:

None

_apply_safety_significance_postprocessing(card, causality_candidates)[source]
Parameters:
Return type:

None

_apply_metamodel_phase2_postprocessing(card, causality_candidates)[source]
Parameters:
Return type:

None

_summarize_primary_evidence_posture(evidence_rows, primary_candidate_id)[source]
Parameters:
  • evidence_rows (Sequence[JsonDict])

  • primary_candidate_id (Optional[str])

Return type:

JsonDict

_fallback_decision_status_from_posture(*, evidence_summary, pattern_posture, passed_minimum_evidence_gate)[source]
Parameters:
  • evidence_summary (JsonDict)

  • pattern_posture (JsonDict)

  • passed_minimum_evidence_gate (bool)

Return type:

str

_fallback_attention_flags_from_posture(*, evidence_summary, pattern_posture, passed_minimum_evidence_gate)[source]
Parameters:
  • evidence_summary (JsonDict)

  • pattern_posture (JsonDict)

  • passed_minimum_evidence_gate (bool)

Return type:

List[str]

_fallback_confidence_and_decision(*, evidence_summary, passed_minimum_evidence_gate)[source]
Parameters:
  • evidence_summary (JsonDict)

  • passed_minimum_evidence_gate (bool)

Return type:

JsonDict

_candidate_recurrence(candidate)[source]
Parameters:

candidate (Optional[JsonDict])

Return type:

JsonDict

_primary_recurrence_why_primary(candidate)[source]
Parameters:

candidate (Optional[JsonDict])

Return type:

List[str]

_primary_recurrence_uncertainties(candidate)[source]
Parameters:

candidate (Optional[JsonDict])

Return type:

List[str]

_recurrence_review_questions(candidate)[source]
Parameters:

candidate (Optional[JsonDict])

Return type:

List[str]

_candidate_common_cause(candidate)[source]
Parameters:

candidate (Optional[JsonDict])

Return type:

JsonDict

_candidate_temporal_posture(candidate)[source]
Parameters:

candidate (Optional[JsonDict])

Return type:

str

_candidate_evidence_posture(candidate)[source]
Parameters:

candidate (Optional[JsonDict])

Return type:

str

_build_causal_depth_summary(*, primary_candidate, selected_candidates)[source]
Parameters:
  • primary_candidate (Optional[JsonDict])

  • selected_candidates (Sequence[JsonDict])

Return type:

JsonDict

_build_unresolved_gaps(*, primary_candidate, evidence_summary, pattern_posture, analyst_attention_flags, causal_depth_summary=None, sensitivity_any_change=False, novel_pattern_flag=False, similar_event_list=None)[source]

Deeper gap list — links depth layers, sensitivity table, novel patterns, and OE coverage.

Parameters:
  • primary_candidate (Optional[JsonDict])

  • evidence_summary (JsonDict)

  • pattern_posture (JsonDict)

  • analyst_attention_flags (Sequence[str])

  • causal_depth_summary (Optional[JsonDict])

  • sensitivity_any_change (bool)

  • novel_pattern_flag (bool)

  • similar_event_list (Optional[JsonDict])

Return type:

List[str]

static _build_effectiveness_monitoring_plan(*, primary_candidate, recommended_actions)[source]

Depth-stratified monitoring plan.

Proximate → equipment-health indicator (recurrence / precursor anomaly) Contributing → process/procedure adherence indicator (PM compliance, WO closure) Root → programmatic/systemic indicator (fleet OE recurrence, AMP review)

Parameters:
  • primary_candidate (Optional[JsonDict])

  • recommended_actions (Sequence[JsonDict])

Return type:

List[JsonDict]

_build_prevention_analysis(*, card, causality_candidates, pm_compliance, telemetry_summary, event=None)[source]

F-3 — deterministic ‘why was it not prevented?’ defense-in-depth assessment.

The metamodel requires the RCA card to state which barriers failed, which held, and why (a first-class output). The existing structural barrier_analysis only maps which safety functions a scored candidate impacts; it does not explain why the failure was not prevented. This assesses three defense-in-depth layers for the primary cause from data already on hand — no new inputs, no speculation:

  • preventive_maintenance — from pm_compliance surveillance/PM checks (a failed check is a prevention gap);

  • condition_monitoring — from telemetry detection (anomaly precursors present ⇒ monitoring held; telemetry present but no precursor ⇒ a detection gap; no telemetry ⇒ not evaluated);

  • protection_logic — from the primary candidate’s barrier_logic hard gate (a retained primary passed the gate, so protection did not preclude the cause ⇒ gap; degraded/absent inputs ⇒ not evaluated).

Honest by construction: any layer without inputs is not_evaluated rather than being asserted as a failure. Additive card block; ranking untouched.

Parameters:
Return type:

JsonDict

static _build_human_performance_assessment(*, selected_candidates, recommended_actions)[source]

Step 6 — Human and Organisational Performance Assessment.

Scans retained candidates for H/I/J/K categories and produces a structured block for the RCA card. When no such candidates are present, returns an applicable=False record so the field is always populated.

Parameters:
  • selected_candidates (Sequence[JsonDict])

  • recommended_actions (Sequence[JsonDict])

Return type:

JsonDict

_primary_common_cause_why_primary(candidate, causality_candidates)[source]
Parameters:
Return type:

List[str]

_primary_common_cause_uncertainties(candidate, causality_candidates)[source]
Parameters:
Return type:

List[str]

_common_cause_review_questions(candidate, causality_candidates)[source]
Parameters:
Return type:

List[str]

_confidence_rank(label)[source]
Parameters:

label (str)

Return type:

int

_cap_confidence_label(label, maximum)[source]
Parameters:
  • label (Optional[str])

  • maximum (str)

Return type:

str

_score_gap_to_runner_up(selected_candidates)[source]
Parameters:

selected_candidates (List[JsonDict])

Return type:

float

_summarize_primary_pattern_posture(primary_candidate, evidence_summary, selected_candidates, causality_candidates, *, passed_minimum_evidence_gate, fallback_used)[source]
Parameters:
  • primary_candidate (Optional[JsonDict])

  • evidence_summary (JsonDict)

  • selected_candidates (List[JsonDict])

  • causality_candidates (Optional[JsonDict])

  • passed_minimum_evidence_gate (bool)

  • fallback_used (bool)

Return type:

JsonDict

_calibrate_primary_confidence(posture)[source]
Parameters:

posture (JsonDict)

Return type:

str

_compute_conclusion_type(top, selected_candidates, calibrated_confidence_label, actuation_type)[source]

Derives the epistemic standing of the RCA conclusion.

Mirrors Stage D A/B-series tiering thresholds (composite ≥ 0.45 AND evidence ≥ 0.35 = A-series) without requiring an explicit series label on the candidate object.

design_signal actuation: the pipeline is verifying a design-basis response, not diagnosing a failure. All anomaly-based FM candidates are speculative by definition, so the minimum output is hypothesis_speculative regardless of scoring.

Parameters:
  • top (Optional[JsonDict])

  • selected_candidates (List[JsonDict])

  • calibrated_confidence_label (str)

  • actuation_type (Optional[str])

Return type:

str

_build_ccf_summary(selected_candidates, causality_candidates)[source]

Builds the rca_card ccf_summary block from the causality engine’s common_cause_summary. Returns None when no common-cause signal was detected (candidate_count_with_common_cause == 0).

affected_trains is assembled from per-candidate common_cause.train_id_in_oos so that all OOS trains in the clustered set are surfaced — the engine’s common_cause_summary does not aggregate this.

Parameters:
Return type:

Optional[JsonDict]

_apply_epistemics_postprocessing(card, causality_candidates)[source]

Enforce epistemics digest rules on the card in-place.

  1. Cap confidence_label at digest.confidence_cap when set.

  2. Set causal_grounding_absent on primary_hypothesis.

  3. Add gap-typed attention flags per §7.4 when ungrounded or absent analyzes support.

Parameters:
Return type:

None

_fallback_card(rca_id, event, selected_candidates, selected_evidence, causality_candidates, evidence_bundle, run_context, prior_errors, tskr_patterns=None, similar_event_list=None)[source]
Parameters:
Return type:

JsonDict

_balanced_fallback_evidence(*, selected_evidence, selected_candidates, max_rows=10)[source]
Parameters:
  • selected_evidence (List[JsonDict])

  • selected_candidates (List[JsonDict])

  • max_rows (int)

Return type:

List[JsonDict]

_enforce_balanced_card_evidence(*, card, selected_candidates, evidence_pool, max_rows)[source]

Tighten LLM-path evidence balance by ensuring in-card alternatives are represented.

Parameters:
Return type:

None

static _validate_and_repair_llm_sections(card, all_input_candidate_ids)[source]

Remove LLM-hallucinated candidate IDs from secondary card sections.

Filters contributing_causes[] and alternatives[] by removing entries whose candidate_id is not in all_input_candidate_ids. Nullifies linked_candidate_id on recommended_actions[] and evidence[] items that reference an invented ID. Does NOT touch primary_hypothesis (handled by the hard-reject gate in synthesize()).

Returns the count of repaired (removed/nullified) items so the caller can set synthesis_quality accordingly.

Parameters:
  • card (JsonDict)

  • all_input_candidate_ids (set)

Return type:

int

_validate_card_semantics(card)[source]
Parameters:

card (JsonDict)

Return type:

List[str]

_all_claims_cited(card)[source]
Parameters:

card (JsonDict)

Return type:

bool

_passes_minimum_evidence_gate(card, event_severity=None)[source]
Parameters:
Return type:

bool

_normalize_confidence_label(label)[source]
Parameters:

label (Optional[str])

Return type:

str