Skip to content

API Reference parrot_formdesigner.core.events

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

parrot_formdesigner.core.events

View source

Form lifecycle event models for parrot-formdesigner.

This module defines the Pydantic models and typed exception used by the form lifecycle events system (FEAT-188). All later modules (event_registry, event_dispatcher, schema extension, handlers, renderer) import from here.

FEAT-329 extends the same pattern with the visit.* namespace: visit / assignment lifecycle events reuse the FEAT-188 registry and semantics (context → handler → EventResolution | FormEventAbort) without a FormSchema in the path.

Class EventResolution

Return value of a form lifecycle event handler.

All fields are optional. An empty EventResolution() is a valid no-op: the dispatcher will leave all inputs unchanged.

Fields:

Field Type Default Description
payload Mapping[str, Any] | None None When non-None, replaces the submission payload passed to the next processing step.
schema_overrides Mapping[str, Any] | None None When non-None, shallow-merges into the serialised FormSchema dict (top-level keys only, per spec §7 shallow-merge decision for MVP).
metadata Mapping[str, Any] | None None Added to FormEventContext.extra for downstream consumers (audit, tracing).
user_message str | None None Only meaningful for onError; overrides the error message returned to the end-user.

Class FormEventAbort

Cancels a before* lifecycle event with a typed user-facing response.

Inspired by api/operations.py:150 OperationError. Raising this inside a handler registered for onBeforeOpen or onBeforeSubmit causes the dispatcher to re-raise it immediately so that the calling handler in FormAPIHandler can convert it to the correct HTTP error response (status_code + user_message).

onError is not triggered for FormEventAbort — an abort is a controlled flow, not an unexpected failure (per spec §7).

Parameter Type Default Description
reason str
user_message str
status_code int 403

Attributes:

Attribute Type Description
reason Internal technical reason for the abort (logged, not exposed to end-users).
user_message Human-readable message safe to return in the HTTP body.
status_code HTTP status code for the response (default: 403).

Class FormEventBinding

Declaración por-formulario de un binding evento → handler.

Fields:

Field Type Default Description
handler_ref str Logical handler name, namespaced as '<form_id>.<event>'. At least one dot is required to prevent cross-form collisions (per spec §7 naming decision).
remote bool False When True, the HTML5 client bridges the event to the server via a fetch call to the remote endpoint.
required bool False When True and the handler is not registered, the dispatcher raises RuntimeError instead of silently no-op-ing.
on_failure Literal['abort', 'continue'] 'continue' When the handler runs and fails (raises, times out, or returns an invalid resolution), "abort" rejects the submission via FormEventAbort semantics; "continue" (default) logs the failure and proceeds as if the handler returned EventResolution(). Distinct from required, which governs a MISSING handler.

Class FormEventContext

Payload passed to a form lifecycle event handler.

Fields:

Field Type Default Description
event FormEventName The name of the lifecycle event being dispatched.
form_id str Identifier of the form that owns the event.
tenant str | None Tenant slug used to resolve the handler in the registry.
auth_context Any Resolved auth credentials. Typed as Any to avoid a circular import through core/ → services/.
payload Mapping[str, Any] | None None Submitted data (present only for submit events).
schema_dump Mapping[str, Any] | None None Rendered schema dict (present for open/schema_loaded).
error BaseException | None None The exception that triggered onError (if applicable).
user_message str | None None Mutable error message that onError handlers may replace for friendlier i18n output.
submission_id str | None None onAfterSubmit only — id of the committed submission, so a handler can say which stored row an event is about (FEAT-920).
llm_validation Mapping[str, Any] | None None onAfterSubmit only — the answer-plausibility verdict exactly as persisted in FormSubmission.context["llm_validation"]: the PlausibilityReport JSON dump (audit fields included) plus acknowledged when a review refusal was reconfirmed. A configured check that did not run (on_error="skip" failure, or the annotate rate-limit skip) arrives with status="skipped" and its reason; None means no check was configured or requested (FEAT-920).
extra dict[str, Any] Free-form bag for correlation IDs, tracing data, etc.

Attribute FormEventName

Class FormEventsConfig

Mapa declarado por-formulario de event → binding.

All fields are optional. Forms without an event binding simply skip that hook without any overhead (no-op by default in the dispatcher).

Fields:

Field Type Default Description
onBeforeOpen FormEventBinding | None None Fired before the form is returned to the client. Can mutate schema_dump or abort with FormEventAbort.
onSchemaLoaded FormEventBinding | None None Fired after the structural schema is rendered. Can apply schema_overrides.
onBeforeSubmit FormEventBinding | None None Fired before validation. Can normalise/replace payload or abort with FormEventAbort.
onAfterSubmit FormEventBinding | None None Fired after the submission is stored and forwarded. Side-effects only; return value ignored by dispatcher.
onError FormEventBinding | None None Fired when any unhandled exception escapes submit_data. Can transform user_message; original exception is re-raised.

Class VisitEventContext

Payload passed to a visit lifecycle event handler (FEAT-329).

Mirror of FormEventContext for the visit.* namespace: same context → handler → resolution semantics, but scoped to a visit / assignment rather than a form — no form_id / schema_dump in the path.

Fields:

Field Type Default Description
event VisitEventName The name of the visit lifecycle event being dispatched.
tenant str | None Tenant slug used to resolve the handler in the registry.
auth_context Any Resolved auth credentials. Typed as Any to avoid a circular import through core/ → services/.
event_id str | None None Identifier of the parent Event (FEAT-303), if any.
shift_id str | None None Identifier of the Shift the visit belongs to, if any.
visit_id str | None None Identifier of the Visit being processed, if any.
staff_id str | None None Identifier of the staff member performing the visit.
payload Mapping[str, Any] | None None Event-specific data (artifact metadata, GPS fix, ...).
extra dict[str, Any] Free-form bag for correlation IDs, tracing data, etc.

Attribute VisitEventName

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