Skip to content

API Reference parrot_formdesigner.services.llm_quota

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

parrot_formdesigner.services.llm_quota

View source

Server-side quota for LLM-backed form calls (FEAT-728).

Public forms expose /validate and /data without authentication (services/public_forms.py:13), and both can reach the LLM plausibility checker. This module bounds those calls per identity and form. It is never configured from form schema — a tenant must not be able to raise its own limit (spec AC14).

Class InProcessSlidingWindow

Per-key sliding window on a monotonic clock, bounded by LRU eviction.

Per-worker state: with N gunicorn workers the effective limit is N times the configured one (spec §7). max_keys caps adversarial key growth from anonymous IPs; the least-recently-used key is evicted at the cap.

Parameter Type Default Description
max_keys int 4096
clock Callable[[], float] | None None

Method InProcessSlidingWindow.acquire

Charge one call to key.

Returns allowed=False with the seconds until the oldest hit in the window expires (always >= 1 when denied, so Retry-After is useful).

acquire(key: str, *, limit: int, window_s: float) -> QuotaDecision

Parameter Type Default Description
key str
limit int
window_s float

Returns: QuotaDecision

Class LLMQuota

Quota for LLM-backed form calls, keyed by {tenant}:{form_uid}:{identity}.

Parameter Type Default Description
backend LLMQuotaBackend | None None
enabled bool True
limit int 10
window_s float 60.0
trust_forwarded_for bool False

Attributes:

Attribute Type Description
backend LLMQuotaBackend

Method LLMQuota.identity

The caller's quota identity.

The authenticated user id when navigator populated a session (verified: api/handlers.py:576-580), else the client IP — X-Forwarded-For's first hop only when trust_forwarded_for is on, because that header is client-settable.

identity(request: 'web.Request') -> str

Parameter Type Default Description
request 'web.Request'

Returns: str

Method LLMQuota.acquire

Charge one LLM call. Always allows when enabled is False.

Never raises: a backend failure is logged and allowed, because a limiter outage must not take the submit path down with it.

acquire(request: 'web.Request', *, tenant: str | None, form_uid: str) -> QuotaDecision

Parameter Type Default Description
request 'web.Request'
tenant str | None
form_uid str

Returns: QuotaDecision

Class LLMQuotaBackend

Swap-in point for a shared limiter (e.g. Redis) — see spec §8 Q2.

Method LLMQuotaBackend.acquire

Charge one call to key; return whether it is allowed.

acquire(key: str, *, limit: int, window_s: float) -> QuotaDecision

Parameter Type Default Description
key str
limit int
window_s float

Returns: QuotaDecision

Class QuotaDecision

One limiter answer.

Fields:

Field Type Default Description
allowed bool
retry_after_s int 0

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