form
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). |
| FieldError | promptantic.form.values | Input that can't become a value of the field (e.g. "abc" for a number). |
| FormCancelledError | promptantic.form.target | The user closed the form without submitting it. |
| FormTarget | promptantic.form.target | The schema a form is built from, and how its result is validated. |
| FormValidationError | promptantic.form.target | The finished value doesn't validate. |
| Issue | promptantic.form.target | One problem with a finished value, at a path into it ((): the whole value). |
| 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¶
The UI-independent core: JSON Schema -> form tree -> values -> validation.
Renderers (Textual, prompt-toolkit) build their widgets from the tree of
:func:build_form, check fields with :func:field_errors while the user types,
and hand the finished value to :meth:FormTarget.validate.
UNSET
module-attribute
¶
No value given (distinct from None, which is JSON null).
FormNode
¶
FormNode = (
StringNode
| NumberNode
| BooleanNode
| NullNode
| ChoiceNode
| AnyNode
| ArrayNode
| TupleNode
| ObjectNode
| UnionNode
)
A node of the form tree.
AnyNode
dataclass
¶
ArrayNode
dataclass
¶
Bases: NodeBase
A list of items of one kind.
Source code in src/promptantic/form/nodes.py
BooleanNode
dataclass
¶
Choice
dataclass
¶
ChoiceNode
dataclass
¶
Bases: NodeBase
One of a fixed set of values (enum, const, or oneOf of titled consts).
Source code in src/promptantic/form/nodes.py
FieldError
¶
FormCancelledError
¶
FormTarget
dataclass
¶
The schema a form is built from, and how its result is validated.
Source code in src/promptantic/form/target.py
validate
¶
The validated result (a model instance for Python types).
Raises:
| Type | Description |
|---|---|
FormValidationError
|
With every issue found, not only the first. |
FormValidationError
¶
Bases: ValueError
The finished value doesn't validate.
Source code in src/promptantic/form/target.py
Issue
dataclass
¶
Meta
dataclass
¶
What every node carries besides its kind: labels, default, flags.
Source code in src/promptantic/form/nodes.py
NullNode
dataclass
¶
Bases: NodeBase
Only null (e.g. the None member of a union that isn't just "optional").
Source code in src/promptantic/form/nodes.py
NumberNode
dataclass
¶
Bases: NodeBase
A number; integer for whole numbers.
Source code in src/promptantic/form/nodes.py
ObjectNode
dataclass
¶
Bases: NodeBase
Named fields, plus optionally free keys (additionalProperties with a schema).
Source code in src/promptantic/form/nodes.py
additional
cached
property
¶
additional: FormNode | None
Node for the values of free keys, or None when there are none.
Property
dataclass
¶
One field of an :class:ObjectNode.
Source code in src/promptantic/form/nodes.py
StringNode
dataclass
¶
Bases: NodeBase
Free text, optionally constrained.
Source code in src/promptantic/form/nodes.py
TupleNode
dataclass
¶
Bases: NodeBase
A fixed sequence of positions, each of its own kind (prefixItems).
Source code in src/promptantic/form/nodes.py
UnionNode
dataclass
¶
Bases: NodeBase
One of several alternatives (anyOf / oneOf / several types).
Source code in src/promptantic/form/nodes.py
discriminator
class-attribute
instance-attribute
¶
Property whose value tells the variants apart (OpenAPI / pydantic discriminator).
Variant
dataclass
¶
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 |
Source code in src/promptantic/form/build.py
field_errors
¶
field_errors(node: FormNode, value: Any) -> list[str]
What's wrong with value for this field alone (empty when it fits).
Covers the field's own constraints (length, pattern, format, bounds, item and key counts, allowed choices); the full document is validated at the end.
Source code in src/promptantic/form/values.py
parse_text
¶
parse_text(node: StringNode | NumberNode | AnyNode, text: str) -> Any | Unset
The value typed text stands for; :data:UNSET for empty input.
Raises:
| Type | Description |
|---|---|
FieldError
|
|
Source code in src/promptantic/form/values.py
target_for
¶
target_for(target: type[T]) -> FormTarget[T]
target_for(target: Mapping[str, Any]) -> FormTarget[dict[str, Any]]
target_for(target: type[Any] | Mapping[str, Any]) -> FormTarget[Any]
The form target for a JSON Schema (as a mapping) or a Python type.