Skip to content

API Reference parrot_formdesigner.services.unknown_fields

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

parrot_formdesigner.services.unknown_fields

View source

Extras computation and cap enforcement for the unknown-fields policy.

This module holds the two pure functions that carry the tricky logic in FEAT-458 — deliberately isolated from any form, handler, or database so the hard cases (a declared-but-empty answer, a nested GROUP child, a payload one byte over the cap) are plain unit tests.

This module is intentionally policy-blind: it does not read FormSchema.unknown_fields and imports nothing from the wider package namespace. The caller (the handler) decides what to do with the extras this module computes and the caps it enforces.

Class ExtrasCapExceeded

Raised when captured extras exceed a configured cap.

Parameter Type Default Description
limit Literal['keys', 'bytes']
actual int
maximum int

Attributes:

Attribute Type Description
limit Which cap was exceeded — "keys" or "bytes".
actual The measured value.
maximum The configured ceiling.

Attribute MAX_EXTRA_BYTES

Type: int

Attribute MAX_EXTRA_KEYS

Type: int

Function compute_extra_data

Return the payload's top-level keys that no declared field_id covers.

Pure, synchronous, and policy-free. declared_field_ids MUST come from the recursive traversal — never from sanitized_data.keys(), which omits declared fields whose coerced value was None.

compute_extra_data(payload: dict[str, Any], declared_field_ids: set[str]) -> dict[str, Any]

Parameter Type Default Description
payload dict[str, Any] The submitted answers, AFTER visit_context extraction and AFTER the onBeforeSubmit hook may have replaced them.
declared_field_ids set[str] Every field_id the schema declares, from the recursive traversal (GROUP children and ARRAY item_template included).

Returns: dict[str, Any] — A new dict of the undeclared entries. Empty dict when there are none.

Function enforce_extras_cap

Raise ExtrasCapExceeded when extras exceeds either cap.

Never truncates — truncation would reintroduce the silent-loss defect this feature exists to remove. Does not mutate extras.

enforce_extras_cap(extras: dict[str, Any], *, max_keys: int = MAX_EXTRA_KEYS, max_bytes: int = MAX_EXTRA_BYTES) -> None

Parameter Type Default Description
extras dict[str, Any] The captured undeclared keys to check.
max_keys int MAX_EXTRA_KEYS Maximum number of top-level keys allowed.
max_bytes int MAX_EXTRA_BYTES Maximum serialized (UTF-8 encoded) JSON size, in bytes.

Raises:

  • ExtrasCapExceeded — When the key count or serialized byte size exceeds its cap.

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