Skip to content

API Reference parrot_formdesigner.core.constraints

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

parrot_formdesigner.core.constraints

View source

Field constraints and conditional visibility rules for form fields.

This module defines the data models for field-level constraints (min/max, patterns, file size limits) and the dependency rule system that controls conditional visibility and behavior.

Class ConditionOperator

Operators for field conditions in dependency rules.

Attribute DEFAULT_MAX_INLINE_SIZE

System default (10 MB) for the inline data_url size threshold (FEAT-460).

Class DependencyOperation

An operation that computes or assigns a value from referenced field values.

Used within :class:DependencyRule (as one of operations) and :class:PostDependency (as operation) to express derived/calculated field values.

Fields:

Field Type Default Description
op Literal['copy', 'add', 'subtract', 'multiply', 'divide', 'percent', 'concat', 'format', 'date_diff', 'lookup', 'aggregate'] The operation kind. One of: - "copy" — copy a source field value to target. - "add" / "subtract" / "multiply" / "divide" — arithmetic. - "percent" — compute a percentage. - "concat" — concatenate string operand values. - "format" — apply a format string (use options["template"]). - "date_diff" — compute the difference between two dates (unit via options["unit"], e.g. "days"). - "lookup" — look up a value via an external tool reference (tool ref in options["tool_ref"]). - "aggregate" — aggregate values across repeated-section items (function in options["fn"], e.g. "sum" / "avg" / "count").
operands list[str] List of field reference strings whose current values are the inputs. Must be non-empty. Authored as field_id strings; :func:~parrot_formdesigner.core.resolution. resolve_rule_references (FEAT-393) rewrites them in place to canonical UUID strings (str(field_uid)) at a build boundary — idempotent, since an already-UID-shaped operand validates and passes through unchanged.
target str The field reference that receives the computed value. Same authored-field_id → resolved-UUID-string lifecycle as operands (FEAT-393).
options dict[str, Any] | None None Optional operation-specific configuration (e.g. {"unit": "days"} for date_diff, {"template": "{} {}"} for format).

Class DependencyRule

Rule controlling conditional visibility/behavior of a field or section.

Fields:

Field Type Default Description
groups list[LogicGroup] | None None Alternatives, each AND'd internally and OR'd against the others. When present it REPLACES conditions/logic — the flat pair stays for every rule that does not need nesting.
conditions list[FieldCondition] List of field conditions that must be evaluated.
logic Literal['and', 'or', 'xor', 'not'] 'and' How conditions are combined. One of: - "and": all conditions must be true (default; backward-compatible). - "or": at least one condition must be true. - "xor": exactly one condition must be true. - "not": negates the AND-combination of conditions (i.e. NOT(all true)).
effect Literal['show', 'hide', 'require', 'disable'] 'show' The effect applied when conditions are met.
operations list[DependencyOperation] | None None Optional list of :class:DependencyOperation instances that compute or assign values when the rule is triggered.

Class FieldCondition

A single condition referencing another field's value.

Fields:

Field Type Default Description
field_id str | None None The authored reference to the field to evaluate — a human/YAML/LLM-authored field_id (FEAT-393). Only meaningful when source == "field". Retained as informational input after resolution; it goes stale on rename by design and is ignored at evaluation time once field_uid is set.
field_uid uuid.UUID | None None The resolved, authoritative UID reference (FEAT-393). None until :func:~parrot_formdesigner.core.resolution. resolve_rule_references rewrites the authored field_id at a build boundary. Only meaningful when source == "field".
operator ConditionOperator The comparison operator to apply.
value Any None The value to compare against (not required for IS_EMPTY/IS_NOT_EMPTY).
source str 'field'
key str | None None

Class FieldConstraints

Constraints applied to a form field for validation.

Fields:

Field Type Default Description
min_length int | None None Minimum string length (>= 0).
max_length int | None None Maximum string length (>= 0).
min_value float | None None Minimum numeric value.
max_value float | None None Maximum numeric value.
step float | None None Numeric step increment.
pattern str | None None Regular expression pattern for validation. Validated at construction time to prevent ReDoS from malformed patterns.
pattern_message LocalizedString | None None Human-readable message shown when pattern fails.
min_items int | None None Minimum number of items in array/multi-select fields (>= 0).
max_items int | None None Maximum number of items in array/multi-select fields (>= 0).
allowed_mime_types list[str] | None None Allowed MIME types for file/image fields.
max_file_size_bytes int | None None Maximum file size in bytes for file/image fields (>= 0).
max_inline_size_bytes int | None None Maximum file size (bytes) for inline data_url inclusion. Files above this get blob_ref only. None → system default (DEFAULT_MAX_INLINE_SIZE).
scale_min int | None None Scale minimum (>= 0)
scale_max int | None None Scale maximum (must be > scale_min)
scale_step int | None None Scale step increment (>= 1)
anchor_labels dict[int, LocalizedString] | None None Label for specific scale points

Alias LocalizedString

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

Class LogicGroup

One alternative inside a :class:DependencyRule.

Conditions inside a group are AND'd; the groups themselves are OR'd against each other. That nesting is what a flat conditions list cannot express — "the store is in one of these groups AND the visit is one of these types" needs two groups, not thirteen conditions under a single gate, where and demands all thirteen and or settles for one.

The shape matches the frontend's LogicGroup (navigator-svelte formbuilder/types/schema.ts), which has evaluated groups since before the server could express them.

Fields:

Field Type Default Description
conditions list[FieldCondition] Conditions that must ALL hold for this group to match.

Class PostDependency

A forward dependency: how a field's answered value affects a later field.

PostDependency declares that the owning field's value has a forward effect on a control declared after it. Ordering is validated by :class:~parrot_formdesigner.services.FormValidator.

Fields:

Field Type Default Description
target str The field reference of the field to affect (must be declared after the owning field in the form layout). Authored as a field_id string; resolved in place to a canonical UUID string by :func:~parrot_formdesigner.core.resolution.resolve_rule_references (FEAT-393) — idempotent, same lifecycle as :attr:DependencyOperation.target.
effect Literal['set', 'calc', 'reload_options', 'show', 'hide', 'require', 'cascade_clear'] The effect to apply. "set" and "calc" require an operation; the others are pure visibility/state changes. One of: - "set" — assign a computed value to target (requires operation). - "calc" — calculate and assign a derived value (requires operation). - "reload_options" — hint to clients to refresh the options list of target (async hint; evaluation timing is renderer-specific). - "show" / "hide" — control visibility of target. - "require" — make target required. - "cascade_clear" — clear the value of target.
conditions list[FieldCondition] | None None Optional gating conditions evaluated against the owning field's value (and context). If None, the effect always applies.
logic Literal['and', 'or', 'xor', 'not'] 'and' How conditions are combined (same semantics as :attr:DependencyRule.logic). Default "and".
operation DependencyOperation | None None Required when effect is "set" or "calc".

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