Skip to content

solvi.core.response

Response: the answers of one ask with the flow, the trace, the values and the safeguards.

Response: the answers of one ask with the flow, the trace, every fact's value and the safeguards (System.ask returns one; a TraceStorage loads one back). Moved out of solvi.core.system in 1.0, which re-exports it, so that the stores below the System read a stored response without importing the System.

Fact dataclass

Fact(name: str, value: object, start: int, end: int, source: str, quote: str | None, confidence: float = 1.0, origin: str = 'quoted')

One quoted fact of a response (res.facts): the value with the quote that supports it — fact.quote is the quoted text itself, literally at doc[start:end] of the source named source; the step's confidence and provenance ("quoted", or another kind a producer stated). From the trace, never parsed back from text.

CheckResult dataclass

CheckResult(name: str, questions: list, status: str, hard: bool, reason: str | None = None, then: dict | None = None, missing: list | None = None)

One check of a decision (res.checks): its name, the questions whose flow ran it, its status — "passed", "failed", "skipped" (not run: a failed hard check settled every question that needed it, or — no data — a hard check that could not be planned because inputs it needs are not given) or "error" (it ran and could not be evaluated: an exception, not a bool) — whether it is hard, the reason (a failed check: the reasons it gave with Fail(...), else its docstring's first line, else " is false"; an error: the error; skipped: why), for a failed hard check the answers its then set: {question: answer}, and for a hard check without data the given inputs it misses (missing; None otherwise).

to_dict

to_dict()

As JSON data (an answer as stored: a tuple as a list, "not stated" as "").

Response dataclass

Response(results: dict, flow: object, trace: object, values: dict, ms: float, feasible: bool = True, violations: list | None = None, catalog: object = None, safeguards: list | None = None, model_outputs: int = 0)

Bases: Serial

The answers of one ask, with the flow, the trace, every fact's value and the safeguards. Stability: stable (final: use it, do not subclass; its record format is stable).

A response keeps a strong reference to the System that answered it (for report(): the questions, the answer heads, the replay). Deliberately not a weak one: System(cat, qs).ask(state).report() is common and the temporary System would be gone before the report runs. A response you keep for long keeps its System (and its models) alive; keep res.to_dict() or the stored record instead, or drop the reference with res.detach() (then pass system= to report).

checks property

checks

Every check of this decision's flow as data, in flow order → [CheckResult]: name, questions, status ("passed", "failed", "skipped", "error"), hard, reason (what Fail(...) said), and the answers a failed hard check's then set; then the hard checks that could not be planned for lack of data (guard "no_data"), "skipped" with the missing inputs. In to_dict() (and so in a stored decision) as "checks"; derived from the trace, never parsed from text.

confidence property

confidence

Overall confidence: the probability that every answered question is right — the product of the answers' confidences (errors taken as independent, so it is conservative when answers agree through constraints). Abstained questions are left out; see complete. 1.0 when nothing was answered by a model or a learned part.

complete property

complete

Did every question get an answer (none abstained)?

weakest property

weakest

(question, confidence) of the least confident answer, or None when every question abstained.

not_stated property

not_stated

Questions answered "not stated" (solvi.Unknown): answered — they count in confidence and complete — but the text does not state the value.

overall property

overall

The whole response in one line of data: confidence, weakest answer, answered / abstained, complete, feasible; the questions answered "not stated"; and per answer kind the answered count and the product of their confidences.

facts property

facts

The quoted facts of this response as data: every trace step that quoted its value out of a source text — name, value, the offsets (source[start:end]), the quoted text itself, confidence, provenance. Built from the trace (never parsed from text); empty when nothing was quoted. The whole computed state as data: res.values.

to_dict

to_dict()

model_dump(mode="json"): answers, flow, trace, values, safeguards as JSON-ready data (see Serial).

signature

signature(alg='syndrome')

The signature of this response's trace (solvi.core.store.signature.sign: the input, then every record) — a few numbers to keep next to the stored id; solvi.core.store.signature.locate(res, sig) later names the one record that changed.

state_text

state_text(lang=None)

The computed state for people: each computed fact with its value; a quote's offsets; for anything not computed by plain code, its provenance (quoted by a model, decided, learned) and the model; errors, including rejected (ungrounded) model outputs — in a language (solvi.core._i18n; default: the System's). The facts as data: res.values.

audit

audit(question=None, lang=None)

What each answer rests on and which safeguards fired: given inputs → computed facts → quotes (offsets and quoted text) → model decisions (model, probabilities) → learned parts → checks, rule, constraints → answer; plus the share of the support that is deterministic. print(res.audit()), or res.audit("q").to_dict() for data. lang: the language str() renders in (solvi.core._i18n; default: the System's, "en"); the data is the same in every one. → an Audit of every answer, or the AnswerAudit of one question when question is given.

detach

detach()

Drop this response's reference to the System that answered it (so a response kept for long does not keep the System and its models alive) → the response. Afterwards pass system= to report().

report

report(format='md', question=None, system=None, replay='trusted')

A human-readable report of this decision for an auditor or a customer: each answer, what it rests on, the quotes highlighted in the source text with their offsets, the safeguards that fired, the guarantee line, the models' fingerprints, the trace's hashes and the replay status. format: "md" (Markdown), "html" (one self-contained page, every value escaped) or "data" (a dict). replay: "trusted" (default: deterministic steps re-run, model outputs verified from the record — no model is called), "full" (models re-run too) or False. See solvi.core.store.report.

checks_of

checks_of(resp)

The checks of a response's flow, in flow order → [CheckResult] (see Response.checks). Read from the flow, the trace and the answers alone, so a stored response loaded back (with or without its catalog) gives the same list.