Skip to content

build

Class info

Re-exported classes

Class Module Description
AnyNode promptantic.form.nodes Anything (an empty schema): entered as JSON.
ArrayNode promptantic.form.nodes A list of items of one kind.
BooleanNode promptantic.form.nodes True or false.
Choice promptantic.form.nodes One allowed value of a :class:ChoiceNode.
ChoiceNode promptantic.form.nodes One of a fixed set of values (enum, const, or oneOf of titled consts).
Meta promptantic.form.nodes What every node carries besides its kind: labels, default, flags.
NullNode promptantic.form.nodes Only null (e.g. the None member of a union that isn't just "optional").
NumberNode promptantic.form.nodes A number; integer for whole numbers.
ObjectNode promptantic.form.nodes Named fields, plus optionally free keys (additionalProperties with a schema).
Property promptantic.form.nodes One field of an :class:ObjectNode.
StringNode promptantic.form.nodes Free text, optionally constrained.
TupleNode promptantic.form.nodes A fixed sequence of positions, each of its own kind (prefixItems).
UnionNode promptantic.form.nodes One of several alternatives (anyOf / oneOf / several types).
Variant promptantic.form.nodes One alternative of a :class:UnionNode.

🛈 DocStrings

Build the form tree (:mod:promptantic.form.nodes) from a JSON Schema.

Covers JSON Schema 2020-12 as far as a form can use it: $ref ($defs, JSON pointers, $anchor, $id scopes, via :mod:referencing), allOf (merged), anyOf / oneOf (unions, or choices when every variant is a constant), enum / const, type lists, prefixItems (tuples), additionalProperties / patternProperties (free keys), and the ways schemas say "or null" (type: [..., "null"], a null variant, OpenAPI's nullable). Keywords a form can't use (if/then/else, not, contains, dependentSchemas) are left to validation.

build_form

build_form(schema: JsonSchema) -> FormNode

The form tree for schema (nested parts are built on first access).

Raises:

Type Description
SchemaError

The schema (or a $ref in it) can't be resolved.

Source code in src/promptantic/form/build.py
def build_form(schema: JsonSchema) -> FormNode:
    """The form tree for ``schema`` (nested parts are built on first access).

    Raises:
        SchemaError: The schema (or a ``$ref`` in it) can't be resolved.
    """
    return _node(schema, create_resolver(schema))