app.backend.response_payloads

Small dict-builders for the /api/analyse response payload.

Kept separate from server.py so the FastAPI module stays focused on request orchestration and model lifecycle; these helpers depend on neither.

Functions

fallback_robustness()

Robustness payload when adversarial probing was skipped.

fallback_security()

Security payload for the HF-fallback path.

fallback_uncertainty()

Uncertainty payload when no certainty signal is available.

poe_security(tokens, resampled, ...)

Security payload built from PoE generation outputs.

poe_uncertainty(p_correct)

Uncertainty payload for the PoE path.

app.backend.response_payloads.fallback_robustness() dict[source]

Robustness payload when adversarial probing was skipped.

Returned on the HF-fallback path and when the NLP path can’t compute similarity because BERT is unavailable.

Returns:

{"type": "unavailable"}.

app.backend.response_payloads.fallback_security() dict[source]

Security payload for the HF-fallback path.

No PoE verification is performed against the HF Inference API response, so certified is None (frontend distinguishes this from the True case) and the per-token arrays are empty.

Returns:

Security sub-payload with all PoE-only fields blanked.

app.backend.response_payloads.fallback_uncertainty() dict[source]

Uncertainty payload when no certainty signal is available.

Used both on the HF-fallback path and on the NLP path when KLE computation raises (e.g. NLI scorer hiccup).

Returns:

{"overall": None}.

app.backend.response_payloads.poe_security(tokens: list[str], resampled: list[dict], token_entropies: list[float], stability_radii: list[int], stability_margins: list[float]) dict[source]

Security payload built from PoE generation outputs.

token_entropies is conceptually an uncertainty signal, not a security one; we park it on the security payload because the heatmap already consumes tokens from here, so co-locating avoids cross-payload plumbing for now.

Parameters:
  • tokens – Decoded token strings parallel to token_entropies / stability_radii / stability_margins.

  • resampled – Per-rejection records (see app.backend.hydra_inference.generate() for the schema).

  • token_entropies – Verifier ensemble predictive entropy in nats.

  • stability_radii – Minimum vote flips needed to dethrone the winning token, parallel to tokens.

  • stability_margins – Top-1 minus top-2 verifier-ensemble probability, parallel to tokens.

Returns:

Security sub-payload with certified=True indicating the response went through PoE verification.

app.backend.response_payloads.poe_uncertainty(p_correct: float | None) dict[source]

Uncertainty payload for the PoE path.

For MCQ the input is the uncertainty-head’s p_correct scalar; for NLP the caller substitutes the KLE-derived certainty into the same field so the frontend can render either uniformly.

Parameters:

p_correct – Certainty score in [0, 1] or None when the signal is unavailable for this prompt.

Returns:

{"overall": p_correct}.