Skip to content

API Reference parrot_formdesigner.services._identifiers

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

parrot_formdesigner.services._identifiers

View source

Postgres identifier validation helpers.

Identifiers (schema, table, tenant) cannot be parameterised via $1/$2 placeholders, so they are interpolated into SQL strings. To stay safe, every identifier that reaches the SQL templates MUST be validated with :func:validate_identifier first — anything that does not match the strict whitelist regex is rejected with ValueError.

The accepted shape mirrors a conservative subset of unquoted Postgres identifiers: a leading letter or underscore followed by up to 62 letters/digits/underscores. This is more restrictive than Postgres itself (which allows quoted identifiers with arbitrary characters) but removes the entire class of injection bugs at the source.

Function qualified_table

Return "<schema>"."<table>" after validating both identifiers.

Defense-in-depth: each component is validated against a strict allowlist regex (validate_identifier) AND escaped with standard SQL identifier quoting (" → ""), so even a hypothetical bypass of the regex cannot produce an injection.

qualified_table(schema: str, table: str) -> str

Parameter Type Default Description
schema str Postgres schema name.
table str Table name within that schema.

Returns: str — A double-quoted, dot-qualified table reference safe to interpolate.

Function validate_identifier

Return value if it is a safe Postgres identifier.

validate_identifier(value: str, *, kind: str = 'identifier') -> str

Parameter Type Default Description
value str Candidate identifier (schema, table, tenant slug, etc.).
kind str 'identifier' Human-readable label used in the error message.

Returns: str — The validated identifier (unchanged).

Raises:

  • ValueError — If value is not a string matching the whitelist.

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