solvi.core.schema¶
Pydantic models of solvi's public data: answer types, questions, results, trace records, flows, responses.
pydantic models of solvi's public data: answer types, questions, results, trace records, traces, flows and responses.
solvi's own classes stay plain dataclasses (fast to build inside ask); these models are their serialized form:
res.model_dump() / res.model_dump("json") / res.to_json(), Response.from_json(s, catalog=cat),
Response.model_json_schema(), and system.response_schema() — the same schema with each answer as its closed set.
JSON has no dates, sets, enums or models. Values of the stdlib types the dump flattens — date, datetime, time, Decimal,
UUID, set, frozenset, tuple, also inside lists and dicts — are written with their type next to them (a trace's
init_types, a record's type) and come back as they were, declared or not. For the rest (an enum, a pydantic model, a
dataclass) catalog= (or a System) restores typed values from the facts' types (a producer's return type, the type a given
fact's readers expect, or System(input_model=...)), so a trace restored from JSON replays with the same hashes. A value that is
neither (an untyped enum; an untyped date in a record stored by solvi ≤ 0.7.1) comes back as JSON gave it and is listed
in the loaded trace's unrestored: replay then reports its steps as "not_restored" — no verdict on the data — rather
than as damaged.
AnswerSpec ¶
Bases: BaseModel
An answer type: yes/no, one of options, ordered levels, any subset, a span of a text, a ranking or an estimate;
unknown: "not stated" is a valid answer.
QuoteModel ¶
Bases: BaseModel
A supporting quote: text[start:end] of a given text fact.
ResultModel ¶
Bases: BaseModel
The answer to one question.
RecordModel ¶
Bases: BaseModel
One step of the hash-chained trace. missing: the step produced no value (failed or rejected; see error).
ResponseModel ¶
Bases: BaseModel
A response: answers, the flow, the trace, every fact's value, safeguards.
tag_floats ¶
JSON data with every non-finite float as {"$float": "inf" | "-inf" | "nan"} (strict JSON: no Infinity / NaN). Returns v itself when nothing changes.
untag_floats ¶
The inverse of tag_floats: {"$float": "inf"} → inf. Returns v itself when nothing changes.
dumps ¶
Strict JSON text (json.dumps with allow_nan=False) with non-finite floats tagged (tag_floats).
jsonable ¶
JSON data: pydantic's to_jsonable_python, with sets sorted and non-finite floats tagged (strict JSON).
native ¶
Is v plain JSON data (tuples count: they hash like lists), so it comes back from JSON as it was?
type_tree ¶
What a load needs to give v back from its JSON form, or None when JSON gives it back as it is:
"date" / "datetime" / "time" / "Decimal" / "UUID" for a value of exactly that type that its JSON form restores;
{"k": "list" | "tuple" | "set" | "frozenset", "of": tree} (every item alike) or {..., "items": [tree]} (a set's
items in the order the dump writes them); {"k": "dict", "items": {key: tree}} for the keys that need one;
"?" (UNRESTORABLE) for anything else — an enum, a model, an aware datetime whose zone its text does not carry.
restorable ¶
Does a type tree restore the whole value (no part of it needs a declared type)?
from_tree ¶
A value's JSON form → the value its type tree describes; what does not fit the tree (already restored, edited) is returned as it is.
dump ¶
mode="json": JSON-ready data — non-finite floats tagged ({"$float": "inf"}, see tag_floats), so it is strict JSON.
response_model ¶
ResponseModel with results as an object of the system's questions (or of questions), each answer its closed set: a
pydantic class (solvi serve documents its endpoints with it).
response_schema ¶
ResponseModel's JSON schema with results as an object of the system's questions, each answer its closed set.