guardrails_ai.types

Submodules

Classes

CreateGuardRequest

The required request body to created a Guard in the Guardrails API.

ErrorSpan

Character-level span within validated text that caused a validation failure.

FailResult

The output of a validator when validation fails.

Guard

A configured validation pipeline retrieved from the Guardrails API.

JSONSchema

A strongly typed representation of JSON Schema Draft 2020-12.

OnFail

OnFail is an Enum that represents the different actions that can

Outcome

str(object='') -> str

PassResult

PassResult is the output type of Validator.validate when validation

ReAsk

Represents a pending reask when validation fails and retries are exhausted.

ValidationOutcome

The output from a Guard execution.

ValidationResult

ValidationResult is the output type of Validator.validate and the

ValidationSummary

Per-validator result produced during a Guard execution.

Validator

A validator attached to a Guard, including its configuration.

Package Contents

class guardrails_ai.types.CreateGuardRequest

Bases: pydantic.BaseModel

The required request body to created a Guard in the Guardrails API.

description: str | None
model_config
name: str
output_schema: guardrails_ai.types.json_schema_2020_12.JSONSchema
validators: List[guardrails_ai.types.validator.Validator]
class guardrails_ai.types.ErrorSpan

Bases: pydantic.BaseModel

Character-level span within validated text that caused a validation failure.

Useful for pinpointing failures when validating large chunks of text or streaming output with varying chunk sizes.

end: int
model_config
reason: str
start: int
class guardrails_ai.types.FailResult

Bases: guardrails_ai.types.validation_result.ValidationResult

The output of a validator when validation fails.

classmethod deserialize_outcome(outcome: str | None) Literal[guardrails_ai.types.validation_result.Outcome.FAIL]
error_message: str
error_spans: List[guardrails_ai.types.error_span.ErrorSpan] | None
fix_value: Any | None
outcome: guardrails_ai.types.validation_result.Outcome
class guardrails_ai.types.Guard

Bases: CreateGuardRequest

A configured validation pipeline retrieved from the Guardrails API.

id: str
model_config
class guardrails_ai.types.JSONSchema

Bases: pydantic.BaseModel

A strongly typed representation of JSON Schema Draft 2020-12.

JSON Schema can be either a boolean or an object with various properties. When boolean: - true: validates any instance - false: validates no instance

When object: contains various keywords from different vocabularies.

validate_conditional() JSONSchema

Validate that then/else are only used with if.

validate_contains_constraints() JSONSchema

Validate that minContains and maxContains are used with contains.

validate_length_constraints() JSONSchema

Validate min/max length constraints.

validate_numeric_constraints() JSONSchema

Validate numeric constraints.

classmethod validate_type(v: StringOrStringArray | None) StringOrStringArray | None

Validate that type values are one of the allowed JSON Schema types.

additional_properties: SchemaValue | None
all_of: List[SchemaValue] | None
anchor: str | None
any_of: List[SchemaValue] | None
comment: str | None
const: Any | None
contains: SchemaValue | None
content_encoding: str | None
content_media_type: str | None
content_schema: SchemaValue | None
default: Any | None
definitions: Dict[str, SchemaValue] | None
defs: Dict[str, SchemaValue] | None
dependencies: Dict[str, SchemaValue | List[str]] | None
dependent_required: Dict[str, List[str]] | None
dependent_schemas: Dict[str, SchemaValue] | None
deprecated: bool | None
description: str | None
dynamic_anchor: str | None
dynamic_ref: str | None
else_: SchemaValue | None
enum: List[Any] | None
examples: List[Any] | None
exclusive_maximum: float | int | None
exclusive_minimum: float | int | None
format: str | None
id: str | None
if_: SchemaValue | None
items: SchemaValue | None
max_contains: int | None
max_items: int | None
max_length: int | None
max_properties: int | None
maximum: float | int | None
min_contains: int | None
min_items: int | None
min_length: int | None
min_properties: int | None
minimum: float | int | None
model_config
multiple_of: float | int | None
not_: SchemaValue | None
one_of: List[SchemaValue] | None
pattern: str | None
pattern_properties: Dict[str, SchemaValue] | None
prefix_items: List[SchemaValue] | None
properties: Dict[str, SchemaValue] | None
property_names: SchemaValue | None
read_only: bool | None
recursive_anchor: bool | None
recursive_ref: str | None
ref: str | None
required: List[str] | None
schema_: str | None
then: SchemaValue | None
title: str | None
type: StringOrStringArray | None
unevaluated_items: SchemaValue | None
unevaluated_properties: SchemaValue | None
unique_items: bool | None
vocabulary: Dict[str, bool] | None
write_only: bool | None
class guardrails_ai.types.OnFail

Bases: str, enum.Enum

OnFail is an Enum that represents the different actions that can be taken when a validation fails.

REASK

On failure, Reask the LLM.

Type:

Literal[“reask”]

FIX

On failure, apply a static fix.

Type:

Literal[“fix”]

FILTER

On failure, filter out the invalid values.

Type:

Literal[“filter”]

REFRAIN

On failure, refrain from responding; return an empty value.

Type:

Literal[“refrain”]

NOOP

On failure, do nothing.

Type:

Literal[“noop”]

EXCEPTION

On failure, raise a ValidationError.

Type:

Literal[“exception”]

FIX_REASK

On failure, apply a static fix, check if the fixed value passed validation, if not then reask the LLM.

Type:

Literal[“fix_reask”]

CUSTOM

On failure, call a custom function with the invalid value and the FailResult’s from any validators run on the value.

Type:

Literal[“custom”]

Initialize self. See help(type(self)) for accurate signature.

CUSTOM = 'custom'
EXCEPTION = 'exception'
FILTER = 'filter'
FIX = 'fix'
FIX_REASK = 'fix_reask'
NOOP = 'noop'
REASK = 'reask'
REFRAIN = 'refrain'
class guardrails_ai.types.Outcome

Bases: str, enum.Enum

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to ‘utf-8’. errors defaults to ‘strict’.

Initialize self. See help(type(self)) for accurate signature.

FAIL = 'fail'
PASS = 'pass'
class guardrails_ai.types.PassResult

Bases: guardrails_ai.types.validation_result.ValidationResult

PassResult is the output type of Validator.validate when validation succeeds.

class ValueOverrideSentinel
classmethod deserialize_outcome(outcome: str | None) Literal[guardrails_ai.types.validation_result.Outcome.PASS]
classmethod deserialize_value_override(value_override: Any | None) ValueOverrideSentinel | Any | None
serialize_value_override(value_override: Any | None) Any | None
outcome: guardrails_ai.types.validation_result.Outcome
value_override: Any | None
class guardrails_ai.types.ReAsk

Bases: pydantic.BaseModel

Represents a pending reask when validation fails and retries are exhausted.

fail_results: List[guardrails_ai.types.fail_result.FailResult] | None
incorrect_value: Any | None
model_config
class guardrails_ai.types.ValidationOutcome

Bases: pydantic.BaseModel, Generic[OT]

The output from a Guard execution.

Type parameter OT is bound to str | List | Dict and reflects the shape of validated_output.

call_id: str
error: str | None
model_config
raw_llm_output: str | None
reask: guardrails_ai.types.reask.ReAsk | None
validated_output: OT | None
validation_passed: bool | None
validation_summaries: List[guardrails_ai.types.validation_summary.ValidationSummary] | None
class guardrails_ai.types.ValidationResult

Bases: pydantic.BaseModel

ValidationResult is the output type of Validator.validate and the abstract base class for all validation results.

metadata: Dict[str, Any] | None
model_config
outcome: Outcome
validated_chunk: Any | None
class guardrails_ai.types.ValidationSummary

Bases: pydantic.BaseModel

Per-validator result produced during a Guard execution.

error_spans: List[guardrails_ai.types.error_span.ErrorSpan] | None
failure_reason: str | None
model_config
property_path: str | None
validator_name: str
validator_status: Literal['pass'] | Literal['fail']
class guardrails_ai.types.Validator

Bases: pydantic.BaseModel

A validator attached to a Guard, including its configuration.

args: List[Any] | None = None
id: str
kwargs: Dict[str, Any]
model_config
on: str | None
on_fail: guardrails_ai.types.on_fail.OnFail | None