Skip to content

API Reference parrot_formdesigner.core.schema

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.core.schema

View source

Core form schema data models.

This module defines the canonical Pydantic models for form structure: FormField, FormSubsection, FormSection, SubmitAction, FormSchema, and RenderedForm. These models are the foundation of the entire forms abstraction layer.

Alias AuditTrailConfig

Re-exported from parrot_formdesigner.core.audit_trail.AuditTrailConfig.

Alias AuthConfig

Re-exported from parrot_formdesigner.core.auth.AuthConfig.

Attribute BUILTIN_METADATA_SOURCE_NAMES

Type: frozenset[str]

Alias DependencyRule

Re-exported from parrot_formdesigner.core.constraints.DependencyRule.

Alias FieldConstraints

Re-exported from parrot_formdesigner.core.constraints.FieldConstraints.

Alias FieldOption

Re-exported from parrot_formdesigner.core.options.FieldOption.

Alias FieldType

Re-exported from parrot_formdesigner.core.types.FieldType.

Class FormDialect

Wire dialect served by the form contract endpoints (FEAT-650).

JSON_SCHEMA keeps the legacy JsonSchemaRenderer body on GET /forms/{uid}/schema; A2UI serves the FEAT-544 createSurface envelope. GET /forms/{uid} ignores this flag — it always returns the raw FormSchema.

Alias FormEventsConfig

Re-exported from parrot_formdesigner.core.events.FormEventsConfig.

Class FormField

A single field within a form section.

FormField is self-referential: GROUP fields can have children, and ARRAY fields can have an item_template defining the repeated element.

Fields:

Field Type Default Description
field_uid uuid.UUID Stable, immutable UUID4 identity for this field (FEAT-393). Auto-generated on creation and never changes for the lifetime of the field — the primary key for edit operations, rule references, blob storage keys, and internal maps. Client-supplied values are accepted (upsert origin).
field_id str Unique identifier for this field within the form.
field_type FieldType The type of input control to render.
label LocalizedString Human-readable label shown to the user.
description LocalizedString | None None Optional extended description or help text.
placeholder LocalizedString | None None Optional placeholder text shown when the field is empty.
required bool False Whether this field must be filled before submission.
default Any None Default value for the field.
read_only bool False Whether the field is displayed but cannot be edited.
constraints FieldConstraints | None None Validation constraints applied to this field.
options list[FieldOption] | None None Static list of options for select/multi-select fields.
options_source OptionsSource | None None Dynamic options source configuration.
depends_on DependencyRule | None None Pre-dependency rule controlling conditional visibility (references only earlier fields in the form layout).
post_depends list[PostDependency] | None None Forward effects this field has on later fields — e.g. computed values, cascades, or visibility changes on controls declared after this field. None (default) means no forward effects. Validated by :class:~parrot_formdesigner.services.FormValidator.
children list[FormField] | None None Child fields for GROUP type fields.
item_template FormField | None None Template for items in ARRAY type fields.
relation RelationSpec | None None Relational semantics of this field's value (FEAT-456), orthogonal to field_type — e.g. a Many2one reference, a Many2many reference, or a One2many embedded-rows relation. None (default) means the field carries no relational meaning; existing renderers and consumers are unaffected.
meta dict[str, Any] | None None Arbitrary metadata for renderer-specific extensions.
content_type str | None None Optional MIME type hint for the expected answer (e.g. "text/markdown", "text/yaml", "application/json"). None means "inferred from field_type". Advisory only in v1 — no MIME mismatch is rejected at submission time.
accept_content_types list[str] | None None Additional MIME types the field accepts, order-significant (first entry preferred). Surfaced by the renderers so a client knows what it may submit. Including "application/json" on a TEXT/TEXT_AREA field also lets that field carry a dict answer instead of a plain string; see answer_envelope for the typed variant.
answer_envelope Literal['voice'] | None None Opt-in marker declaring that a dict answer on this field follows a known typed envelope rather than being arbitrary JSON. "voice" selects :class:~parrot_formdesigner.core.voice_answer.VoiceAnswerEnvelope and makes the validator enforce that shape. None (default) leaves a submitted dict unvalidated, which is what a field simply holding arbitrary JSON wants.
hint LocalizedString | None None Optional voice hint narrated after the pause; shown as help text by renderers (FEAT-649).
llm_validation bool | None None Per-field LLM plausibility opt-in; None inherits FormSchema.llm_validation.enabled (FEAT-649).

Attributes:

Attribute Type Description
is_relational bool Whether this field carries relational semantics (FEAT-456).

Class FormMetadataField

Declared contextual metadata captured on every form submission.

Metadata fields are computed in a before-save enrichment step on the submit handler. Each declaration produces one or more key / value pairs that are either promoted to a real form_data column (for reserved core keys) or flat-merged into the submission data JSONB alongside the user's answers (no "metadata" sub-object).

Fields:

Field Type Default Description
key str Identifier under which the value is stored. Must be a valid Postgres identifier ([A-Za-z_][A-Za-z0-9_]{0,62}) so it is safe to promote to a column name and stable as a JSONB key. Validated at FormSchema construction.
source MetadataSource Where the value comes from. Built-in sources resolve against the inbound request / session; "callback" invokes a coroutine registered with register_form_callback; "constant" returns default verbatim.
label LocalizedString | None None Optional human-readable label (i18n supported).
callback_ref str | None None Required when source == "callback". Logical callback name looked up in the shared tenant-scoped form callback registry.
default Any None Value substituted when the resolver returns None or a non-required callback fails. Also the source of truth for source == "constant".
required bool False When True, an unresolved value (resolver returns None after default substitution) fails the submission with HTTP 422.
options dict[str, Any] | None None Free-form per-source options bag (e.g. {"header": "Accept-Language"} for locale). Kept loose on purpose to avoid a discriminated union per built-in.

Alias FormPersistenceConfig

Re-exported from parrot_formdesigner.core.persistence.FormPersistenceConfig.

Class FormSchema

The canonical representation of a complete form.

FormSchema is the central data model of the forms abstraction layer. It is platform-agnostic and can be rendered to Adaptive Cards, HTML5, JSON Schema, or any other format via the renderer system.

Fields:

Field Type Default Description
form_uid uuid.UUID Stable, immutable UUID4 identity for this form. Auto-generated on creation and never changes for the lifetime of the form — the primary key for URL routing, registry lookups, storage, and cross-system references (FEAT-389).
form_id str Human-readable slug for this form. Mutable and used for display/search — never as a primary key (FEAT-389).
version str '1.0' Schema version string.
title LocalizedString Human-readable form title.
description LocalizedString | None None Optional description of the form's purpose.
sections list[FormSection] Ordered list of form sections.
submit SubmitAction | None None Optional submission action configuration.
cancel_allowed bool True Whether the user can cancel/dismiss the form.
meta dict[str, Any] | None None Arbitrary metadata for renderer-specific extensions.
created_at datetime | None None Optional creation timestamp (UTC). Populated by storage backends when forms are loaded from persistence; None for ad-hoc forms registered in memory.
tenant str | None None Optional tenant slug. When set, persistence backends use it to resolve the Postgres schema where the form is stored (e.g. "epson" → epson.form_schemas). None falls back to the storage's default schema.
metadata list[FormMetadataField] | None None Declared contextual metadata fields captured on submission.
events FormEventsConfig | None None Optional lifecycle event bindings (FEAT-188). Maps each lifecycle event name (onBeforeOpen, onSchemaLoaded, onBeforeSubmit, onAfterSubmit, onError) to a FormEventBinding that declares the logical handler reference and transport options. When None (default), no lifecycle hooks are invoked — forms without events behave identically to their pre-FEAT-188 state.
form_type FormType FormType.SIMPLE
product_bindings list[str] | None None
published_version str | None None
is_public bool False If True, the form's read and submission URLs are accessible without authentication. Default False. Toggling to True registers the form's public paths in navigator-auth's runtime exclude list; toggling to False or deleting the form unregisters them. (FEAT-241)
persistence FormPersistenceConfig | None None Optional per-form persistence declaration (FEAT-457). When set, this form's submission data (and optionally its own definition body) is written to the declared destination instead of the generic shared storage. None (default) preserves today's behaviour exactly — no breaking change.
unknown_fields UnknownFieldsPolicy UnknownFieldsPolicy.DROP Policy for top-level submission payload keys the schema does not declare (FEAT-458). Defaults to UnknownFieldsPolicy.DROP — discard silently, identical to pre-FEAT-458 behaviour.
dialect FormDialect FormDialect.JSON_SCHEMA Wire dialect served by the form contract endpoints (FEAT-650). Defaults to FormDialect.JSON_SCHEMA to preserve the legacy JSON Schema response body.
voice VoiceFormConfig | None None Optional typed voice-mode configuration block (FEAT-649).
llm_validation LLMValidationConfig | None None Optional LLM answer-plausibility block (FEAT-649).
audit_trail AuditTrailConfig | None None Optional deterministic validation audit-trail block (FEAT-732); None means the summary default.
public_access PublicAccessConfig | None None

Method FormSchema.iter_all_fields

Yield every FormField across all sections, flattening subsections.

NOTE: this is the renderer LAYOUT-ORDER traversal only (sections + subsections, top-level fields) — it does NOT recurse into GROUP children or ARRAY item_template. It is NOT the uniqueness traversal; use :meth:iter_fields_recursive (or the module-level :func:walk_fields) for anything that must see the full tree (FEAT-393, Module 2).

iter_all_fields() -> Iterator[FormField]

Returns: Iterator[FormField]

Method FormSchema.iter_fields_recursive

Yield every FormField in the full tree — sections, subsections, GROUP children, and ARRAY item_template (FEAT-393, Module 2). The canonical traversal for uniqueness validation, rule-reference resolution, and UID lookups.

iter_fields_recursive() -> Iterator[FormField]

Returns: Iterator[FormField]

Class FormSection

A logical grouping of fields within a form.

Sections can be used to organize fields visually and in wizard-style forms each section becomes a separate step.

The fields list may contain both FormField and FormSubsection items in any order. Use :meth:iter_fields to iterate over all FormField instances (flattening through subsections).

Fields:

Field Type Default Description
section_uid uuid.UUID Stable, immutable UUID4 identity for this section (FEAT-393). Auto-generated on creation.
section_id str Unique identifier for this section.
title LocalizedString | None None Optional title displayed as a section header.
description LocalizedString | None None Optional description shown under the section title.
fields list[SectionItem] Ordered list of fields and subsections in this section.
depends_on DependencyRule | None None Dependency rule controlling conditional section visibility.
meta dict[str, Any] | None None Arbitrary metadata for renderer-specific extensions.

Method FormSection.iter_fields

Yield every FormField, flattening through subsections.

iter_fields() -> Iterator[FormField]

Returns: Iterator[FormField]

Class FormSubsection

A visual sub-grouping of fields within a section.

Subsections provide an additional level of organization below sections. They co-exist alongside FormField items in FormSection.fields, giving renderers a grouping boundary (header, divider, container) without creating a full section (which would affect wizard steps, accordion panels, etc.).

Fields:

Field Type Default Description
subsection_uid uuid.UUID Stable, immutable UUID4 identity for this subsection (FEAT-393). Auto-generated on creation.
subsection_id str Unique identifier for this subsection within the form.
title LocalizedString | None None Optional title displayed as a subsection header.
description LocalizedString | None None Optional description shown under the subsection title.
fields list[FormField] List of fields in this subsection.
depends_on DependencyRule | None None Dependency rule controlling conditional visibility.
meta dict[str, Any] | None None Arbitrary metadata for renderer-specific extensions.

Class FormType

Discriminator for the form's structural type.

Attributes:

Attribute Type Description
SIMPLE A straightforward form with a linear set of questions (no survey blocks). This is the default.
PRODUCT A form bound to one or more product programmes (activated via FEAT-302 product_bindings).
SURVEY A form composed of survey-style question blocks (imported from networkninja.forms.question_blocks where block_type == "survey").

Alias LLMValidationConfig

Re-exported from parrot_formdesigner.core.llm_validation.LLMValidationConfig.

Alias LocalizedString

Re-exported from parrot_formdesigner.core.types.LocalizedString.

Attribute MetadataSource

Alias OptionsSource

Re-exported from parrot_formdesigner.core.options.OptionsSource.

Alias PostDependency

Re-exported from parrot_formdesigner.core.constraints.PostDependency.

Alias PublicAccessConfig

Re-exported from parrot_formdesigner.core.public_access.PublicAccessConfig.

Alias RelationSpec

Re-exported from parrot_formdesigner.core.relations.RelationSpec.

Class RenderWarning

Warning emitted when a renderer uses degraded fallback for a field type.

Fields:

Field Type Default Description
field_id str The ID of the field that triggered the fallback.
field_uid uuid.UUID | None None The stable UUID identity of the field that triggered the fallback (FEAT-393), when known. None for warnings emitted outside a per-field rendering context.
field_type str The FieldType.value string (e.g. "signature").
renderer str The renderer name ("html5" | "adaptive_card" | "pdf" | "xforms" | "jsonschema" | "telegram").
reason str Human-readable explanation (e.g. "unsupported in PDF — rendered as placeholder").

Class RenderedForm

Output of a form renderer.

Fields:

Field Type Default Description
content Any The rendered form content (varies by renderer).
content_type str MIME type or format identifier for the content.
style_output Any | None None Optional style-related output from the renderer.
metadata dict[str, Any] | None None Renderer-specific metadata about the rendering process.
warnings list[RenderWarning] [] Degraded-rendering warnings. Empty list when all fields rendered natively. One entry per (field_id, renderer) pair that used FallbackRenderer.

Attribute SectionItem

Class SubmitAction

Defines what happens when a form is submitted.

Fields:

Field Type Default Description
action_type Literal['tool_call', 'endpoint', 'event', 'callback'] How the submission is handled.
action_ref str Reference to the handler (tool name, URL, event name, callback ID).
method str 'POST' HTTP method for endpoint submissions.
confirm_message LocalizedString | None None Optional confirmation message shown before submission.
auth AuthConfig | None None

Class UnknownFieldsPolicy

Policy for top-level submission keys the schema does not declare.

Attributes:

Attribute Type Description
DROP Discard silently (default — pre-FEAT-458 behaviour).
KEEP Capture into FormSubmission.extra_data, subject to caps.
REJECT Fail the submission with 422.

Alias VoiceFormConfig

Re-exported from parrot_formdesigner.core.voice.VoiceFormConfig.

Function derive_stable_identities

Re-derive a schema's child identities from form_uid, in place.

section_uid, subsection_uid and field_uid default to random UUID4s (see the Field(default_factory=uuid.uuid4) declarations above), which is correct when a form is authored but wrong whenever a whole schema is copied: the copy inherits the original's identities verbatim, so two distinct forms end up claiming the same field_uid.

Each uid is derived as a UUID5 of the owning form's identity plus the element's stable local id (section_id / subsection_id / field_id), all of which FormSchema's post-init validator already guarantees unique within the form. That makes this:

  • collision-free — a different form_uid yields a different uid for every child, so no two forms can share one;
  • deterministic — the same (form_uid, local id) pair always produces the same uid, so the operation is idempotent and reproducible;
  • structure-preserving — nothing but the uids changes.

derive_stable_identities(schema: FormSchema, form_uid: uuid.UUID) -> None

Parameter Type Default Description
schema FormSchema The schema to rewrite. Mutated in place.
form_uid uuid.UUID The form identity to derive children from. Normally schema.form_uid; passed explicitly so callers that mint a new identity cannot accidentally derive from the stale one.

Function walk_fields

Yield every FormField, recursing subsections, GROUP children, and ARRAY item_template.

This is the ONE canonical recursive traversal for the full field tree (FEAT-393, Module 2) — the traversal used by uniqueness validation, rule-reference resolution, and UID lookups. It supersedes the divergent walks in iter_all_fields() (layout order only, no nesting), services/validators.py's _collect_fields/_collect_nested_fields, and api/operations.py's _field_index — those are re-keyed onto this helper by later tasks (TASK-1998/1999), not replaced here.

A GROUP field's children and an ARRAY field's item_template are yielded AFTER their parent field (parent-before-children order).

walk_fields(items: Iterable[SectionItem]) -> Iterator[FormField]

Parameter Type Default Description
items Iterable[SectionItem] A section's fields list (FormField and/or FormSubsection items).

Returns: Iterator[FormField]

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally