Files
DocsGPT/docsgpt/core/settings/guardrails.py
T
arc53-machine 95d0799494 refactor(settings): tighten types on closed choices, containers and bounds
Enum-like settings whose allowed values were only listed in a comment are
now Literal types, so a typo fails at startup with a message naming the
allowed values instead of falling through to a default with a warning
(or, for VECTOR_STORE, failing on first use):

  AUTH_TYPE, VECTOR_STORE, STORAGE_TYPE, URL_STRATEGY, OCR_BACKEND,
  OCR_ENGINE, SANDBOX_BACKEND, DOC_PARSER_ENGINE, TTS_PROVIDER, STT_PROVIDER

Each keeps a before-validator that strips and lower-cases the value, since
the registries that consume them already lower-cased at the use site, and
AUTH_TYPE maps the "None"/"none"/"" spellings a .env file carries to None
(it was the string "None" before, which only worked because nothing
compared against it). An empty TTS/STT provider still means "off".
LLM_PROVIDER stays a plain str because providers are plugin-extensible.

Containers are typed (dict[str, int], list[str], dict[str, Any]) instead
of bare dict/list, six fields that were Optional with a non-None default
are plain, and integer settings whose description already states a range
carry it as a constraint (ge=0 for "0 disables", ge=1 for counts that
cannot be zero, 0 < threshold <= 1).
2026-09-17 11:08:50 +01:00

41 lines
1.7 KiB
Python

"""Agent guardrails."""
from __future__ import annotations
from typing import Any, Optional
from pydantic import Field
from docsgpt.core.settings._shared import SettingsGroup
class GuardrailSettings(SettingsGroup):
"""Input/output checks every agent runs, and the floor no agent may weaken."""
GUARDRAILS_ENABLED: bool = Field(default=True, description="Master switch; False disables every stage.")
GUARDRAILS_CHECKS_ENABLED: list[str] = Field(
default=[], description="Allowlist of GuardrailCreator.checks keys; empty means every registered check."
)
GUARDRAILS_FLOOR: dict[str, Any] = Field(
default={},
description=(
"A GuardrailsConfig fragment every agent inherits and cannot weaken; agents may add controls or "
'make an action stricter, never looser. "enabled" is required; without it the floor parses but '
'applies to nothing. Example: {"enabled": true, "mode": "scan_all", "controls": [{"check": '
'"secrets", "stage": "output", "action": "redact"}]}'
),
)
GUARDRAILS_JUDGE_MODEL: Optional[str] = Field(
default=None, description="Judge model for the topic/policy checks; unset reuses the request's model."
)
GUARDRAILS_STORE_SCANNED_TEXT: bool = Field(
default=False,
description=(
"Persist scanned text alongside guardrail_events. Off by default: pre-redaction text is exactly the "
"material a PII control exists to keep out of storage."
),
)
GUARDRAILS_EVENTS_RETENTION_DAYS: int = Field(
default=30, ge=1, description="Days guardrail events are kept before the cleanup task removes them."
)