Skip to content

API Reference parrot_formdesigner.services.validators

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

parrot_formdesigner.services.validators

View source

Platform-agnostic form validation for FormSchema.

This module provides FormValidator and ValidationResult for validating form submission data against FormSchema constraints. The validator is async-native to support ASYNC_REMOTE and UNIQUE validation callbacks.

Migrated and enhanced from parrot/integrations/msteams/dialogs/validator.py.

Alias AuthContext

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

Alias CheckId

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

Alias CheckOutcome

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

Alias ConditionOperator

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

Alias DependencyOperation

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

Attribute EMAIL_PATTERN

Alias FieldType

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

Alias FormField

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

Alias FormSchema

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

Alias FormSection

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

Class FormValidator

Platform-agnostic validator for FormSchema data.

Validates form submission data against FormSchema constraints, including required checks, type coercion, regex patterns, numeric bounds, cross-field rules, and circular dependency detection.

All validation methods are async to support ASYNC_REMOTE and UNIQUE validation callbacks specified via FormField.meta.

Method FormValidator.validate

Validate all form submission data against the schema.

Conditional visibility is resolved first, and a field the form did not display is not required — see the note at the resolution call.

validate(form: FormSchema, data: dict[str, Any], *, locale: str = 'en', auth_context: AuthContext | None = None, location_vars: dict[str, Any] | None = None, visit_context: dict[str, Any] | None = None, trace: ValidationTraceCollector | None = None) -> ValidationResult

Parameter Type Default Description
form FormSchema The FormSchema to validate against.
data dict[str, Any] Submitted form data keyed by field_id.
locale str 'en' Locale for error message resolution.
auth_context AuthContext | None None Optional runtime auth context for REMOTE_RESPONSE fields.
location_vars dict[str, Any] | None None Org-graph location variables, forwarded to rule resolution. A rule reading one of these evaluates against nothing when it is omitted, which reads as "not shown" and so relaxes that field's required check — pass the same context the renderer used to keep both sides in agreement.
visit_context dict[str, Any] | None None Visit-level metadata, forwarded to rule resolution with the same caveat as location_vars.
trace ValidationTraceCollector | None None Optional collector (FEAT-732). When given, the result carries a sealed ValidationTrace; when None validation is unchanged.

Returns: ValidationResult — ValidationResult with field-level errors and sanitized data.

Method FormValidator.validate_field

Validate a single field value against its constraints.

validate_field(field: FormField, value: Any, *, all_data: dict[str, Any] | None = None, locale: str = 'en', auth_context: AuthContext | None = None, required: bool | None = None, trace: ValidationTraceCollector | None = None) -> list[str]

Parameter Type Default Description
field FormField The FormField definition.
value Any The submitted value.
all_data dict[str, Any] | None None Full submission data for cross-field validation.
locale str 'en' Locale for error message resolution.
auth_context AuthContext | None None Optional runtime auth context for REMOTE_RESPONSE fields.
required bool | None None Overrides field.required for this call. validate passes the rule-resolved value, so a field the form never displayed is not demanded; None keeps the schema default.
trace ValidationTraceCollector | None None Optional collector (FEAT-732), forwarded into the voice-envelope recursion. Never changes the return value.

Returns: list[str] — List of error messages (empty list if valid).

Method FormValidator.validate_rules

Validate rule integrity for all fields in the form.

Checks:

  • Every field_id referenced in depends_on.conditions, post_depends.conditions, operation operands, and post_depends.target / operation target resolves to a real field in the form.
  • Ordering: depends_on conditions may only reference fields declared earlier; post_depends.target (and set/calc operation targets) may only reference fields declared later.
  • Operator/type compatibility (best-effort): numeric operators (gt/lt/gte/lte) and arithmetic operations must reference numeric field types; unknown field types pass silently.

validate_rules(form: FormSchema) -> list[str]

Parameter Type Default Description
form FormSchema FormSchema to validate.

Returns: list[str] — List of human-readable error strings (empty when all rules pass).

Method FormValidator.check_schema

Check a form schema for structural issues without submitted data.

Detects circular dependency references (including post_depends and operation edges) and validates rule integrity (references, ordering, type compatibility).

check_schema(form: FormSchema) -> list[str]

Parameter Type Default Description
form FormSchema FormSchema to analyze.

Returns: list[str] — List of human-readable error strings (empty if no issues found).

Alias LocalizedString

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

Attribute PHONE_PATTERN

Alias RemoteResponseResolver

Re-exported from parrot_formdesigner.services.remote_response_resolver.RemoteResponseResolver.

Alias RemoteResponseSpec

Re-exported from parrot_formdesigner.services.remote_response_resolver.RemoteResponseSpec.

Alias SkipReason

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

Attribute URL_PATTERN

Class ValidationResult

Result of validating a form submission.

Fields:

Field Type Default Description
is_valid bool Whether the entire submission passed validation.
errors dict[str, list[str]] Field-level error messages keyed by field_id.
sanitized_data dict[str, Any] Type-coerced and sanitized form data.
extra_data dict[str, Any] Top-level payload keys with no matching declared field_id (FEAT-458). REPORTED, never judged — the validator reads no policy field. {} when the payload matches the schema exactly, or on the __circular__/__rules__ early returns.
trace ValidationTrace | None None Sealed deterministic evidence (FEAT-732), or None when no collector was passed.

Alias ValidationTrace

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

Alias ValidationTraceCollector

Re-exported from parrot_formdesigner.services.validation_trace.ValidationTraceCollector.

Alias VoiceAnswerEnvelope

Re-exported from parrot_formdesigner.core.voice_answer.VoiceAnswerEnvelope.

Alias VoiceEvidenceEnvelope

Re-exported from parrot_formdesigner.core.voice_answer.VoiceEvidenceEnvelope.

Alias callable_identity

Re-exported from parrot_formdesigner.services.validation_trace.callable_identity.

Alias compute_extra_data

Re-exported from parrot_formdesigner.services.unknown_fields.compute_extra_data.

Alias file_type_allowed

Re-exported from parrot_formdesigner.core.mime_match.file_type_allowed.

Alias is_valid_iso_country_code

Re-exported from parrot_formdesigner.core._location_data.is_valid_iso_country_code.

Alias is_voice_envelope

Re-exported from parrot_formdesigner.core.voice_answer.is_voice_envelope.

Attribute logger

Alias schema_fingerprint

Re-exported from parrot_formdesigner.services.validation_trace.schema_fingerprint.

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