Skip to content

API Reference parrot.semantic.governance.guard

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

parrot.semantic.governance.guard

View source

Positive SQL guard: single SELECT, allowlisted tables/columns/functions, forced LIMIT.

Attribute DEFAULT_ALLOWED_FUNCTIONS

Type: frozenset[str]

Alias Limits

Re-exported from parrot.semantic.models.Limits.

Alias ModelPolicy

Re-exported from parrot.semantic.policy.ModelPolicy.

Alias PhysicalSchema

Re-exported from parrot.semantic.loader.PhysicalSchema.

Class PositiveGuard

Positive allowlist over a qualified, governed query AST.

Parameter Type Default Description
schema PhysicalSchema Model-owned physical schema map.
allowed_functions frozenset[str] Effective upper-case function allowlist.
limits Limits Policy row limits (default injected, max clamped).

Method PositiveGuard.check_and_limit

Exactly one exp.Select root (CTEs allowed); every table/column in schema; functions allowlisted; no exp.Command/DDL/DML; inject (policy default) or clamp (policy max) LIMIT.

check_and_limit(tree: exp.Expression, *, trusted_nodes: set[int] | None = None) -> exp.Expression

Parameter Type Default Description
tree exp.Expression Qualified query AST (mutated in place for the LIMIT).
trusted_nodes set[int] | None None Identities of pipeline-injected nodes (RLS/masking); only these may use functions outside the allowlist. Caller-supplied nodes are never trusted.

Returns: exp.Expression — The same tree with an enforced LIMIT.

Raises:

  • SemanticValidationError — codes "not_select", "unknown_table", "unknown_column", "function_not_allowed", "command_forbidden", "invalid_limit".

Alias SemanticValidationError

Re-exported from parrot.semantic.errors.SemanticValidationError.

Function effective_allowed_functions

DEFAULT ∪ (extra or ∅) ∪ policy.allowed_functions — additive only (§8 Q4).

effective_allowed_functions(policy: ModelPolicy, extra: frozenset[str] | None) -> frozenset[str]

Parameter Type Default Description
policy ModelPolicy Model policy contributing per-model extensions.
extra frozenset[str] | None Toolkit-level additive extensions.

Returns: frozenset[str] — The upper-cased effective allowlist.

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