Skip to content

API Reference parrot_formdesigner.services.metadata_enricher

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

parrot_formdesigner.services.metadata_enricher

View source

Before-save submission metadata enrichment.

Given a validated submission, a form schema with declared metadata entries, and the inbound aiohttp request, this module resolves every declared field, splits the resulting keys into the "core" set (promoted to typed FormSubmission columns) and the "extra" set (flat-merged into the submission data JSONB).

The enricher is intentionally a pure function — no HTTP, no DB — so it is trivial to unit-test against stubbed requests.

Alias AuthContext

Re-exported from parrot_formdesigner.services.auth_context.AuthContext.

Alias BUILTIN_METADATA_SOURCES

Re-exported from parrot_formdesigner.services.metadata_sources.BUILTIN_METADATA_SOURCES.

Alias CORE_METADATA_COLUMNS

Re-exported from parrot_formdesigner.services.submissions.CORE_METADATA_COLUMNS.

Alias FormMetadataField

Re-exported from parrot_formdesigner.core.schema.FormMetadataField.

Alias FormSchema

Re-exported from parrot_formdesigner.core.schema.FormSchema.

Alias FormSubmission

Re-exported from parrot_formdesigner.services.submissions.FormSubmission.

Alias MetadataCallbackInput

Re-exported from parrot_formdesigner.services.metadata_callbacks.MetadataCallbackInput.

Alias MetadataCallbackOutput

Re-exported from parrot_formdesigner.services.metadata_callbacks.MetadataCallbackOutput.

Class MetadataResolutionError

Raised when a required metadata field cannot be resolved.

The handler maps this to HTTP 422 with the message in errors._metadata.

Function enrich_submission

Resolve declared metadata for a pending submission.

Iterates form.metadata in declaration order, dispatching each entry to either the built-in source resolver (:data:BUILTIN_METADATA_SOURCES) or a registered async callback looked up via :func:get_form_callback with tenant fallback.

enrich_submission(*, request: 'web.Request', form: 'FormSchema', submission: 'FormSubmission', answers: dict[str, Any], auth_context: 'AuthContext') -> tuple[dict[str, Any], dict[str, Any]]

Parameter Type Default Description
request 'web.Request' Inbound aiohttp request, used by built-in resolvers to read session / user / headers.
form 'FormSchema' The form definition; its tenant field drives callback lookup.
submission 'FormSubmission' The in-flight FormSubmission (constructed but not yet stored). Resolvers may read its existing fields (e.g. submission_id, created_at).
answers dict[str, Any] Sanitized form answers from the validator.
auth_context 'AuthContext' Runtime auth context forwarded to callbacks.

Returns: tuple[dict[str, Any], dict[str, Any]] — Tuple (core_overrides, extra_flat) where core_overrides is a dict whose keys are a subset of CORE_METADATA_COLUMNS (to be applied via submission.model_copy(update=...)) and extra_flat is a dict of remaining keys to merge into submission.data.

Raises:

  • MetadataResolutionError — When a required=True entry cannot be resolved, or when a callback fan-out returns an invalid identifier as a key, or when a resolved key would collide with an existing answer in answers.

Alias get_form_callback

Re-exported from parrot_formdesigner.services.callback_registry.get_form_callback.

Attribute logger

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