Guardrail Config • AI Agent SDK

GuardrailConfig: Configuration for guardrails and safety validation.

GuardrailConfig

Defined in the Feature Configs module.

AI Agent

Configuration for guardrails and safety validation.

Consolidates: guardrail, max_guardrail_retries, policy

Properties

ResponseField Optional

No description available.

ResponseField Optional[str]

No description available.

ResponseField int

No description available.

ResponseField Union[str, GuardrailAction]

No description available.

ResponseField Optional

No description available.

ResponseField List[str]

No description available.

Internal & Generic Methods
  • to_dict: Convert to dictionary.

Usage

python
# With validator function
    Agent(guardrails=my_validator_fn)

    # With a string: an LLM-validation prompt (not a preset name)
    Agent(guardrails="Ensure the response is polite")

    # With a preset (sets max_retries only) plus a validator
    Agent(guardrails=["strict", {"validator": my_validator_fn}])

    # For tool policy enforcement, use the dedicated `policy` param instead:
    Agent(policy=PolicyEngine(...))  # policy strings on guardrails are NOT enforced

    # With config
    Agent(guardrails=GuardrailConfig(
        validator=my_validator_fn,
        max_retries=3,
        on_fail="retry",  # only "retry" is implemented
    ))

    # With LLM-based validation
    Agent(guardrails=GuardrailConfig(
        llm_validator="Ensure response is helpful and safe",
        max_retries=2,
    ))

Source

View on GitHub

praisonaiagents/config/feature_configs.py at line 585


Related Documentation