guardrails_ai.types¶
Submodules¶
- guardrails_ai.types.error_span
- guardrails_ai.types.fail_result
- guardrails_ai.types.guard
- guardrails_ai.types.json_schema_2020_12
- guardrails_ai.types.on_fail
- guardrails_ai.types.pass_result
- guardrails_ai.types.reask
- guardrails_ai.types.validation_outcome
- guardrails_ai.types.validation_result
- guardrails_ai.types.validation_summary
- guardrails_ai.types.validator
Classes¶
The required request body to created a Guard in the Guardrails API. |
|
Character-level span within validated text that caused a validation failure. |
|
The output of a validator when validation fails. |
|
A configured validation pipeline retrieved from the Guardrails API. |
|
A strongly typed representation of JSON Schema Draft 2020-12. |
|
OnFail is an Enum that represents the different actions that can |
|
str(object='') -> str |
|
PassResult is the output type of Validator.validate when validation |
|
Represents a pending reask when validation fails and retries are exhausted. |
|
The output from a Guard execution. |
|
ValidationResult is the output type of Validator.validate and the |
|
Per-validator result produced during a Guard execution. |
|
A validator attached to a Guard, including its configuration. |
Package Contents¶
- class guardrails_ai.types.CreateGuardRequest¶
Bases:
pydantic.BaseModelThe required request body to created a Guard in the Guardrails API.
- model_config¶
- output_schema: guardrails_ai.types.json_schema_2020_12.JSONSchema¶
- validators: List[guardrails_ai.types.validator.Validator]¶
- class guardrails_ai.types.ErrorSpan¶
Bases:
pydantic.BaseModelCharacter-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.
- model_config¶
- class guardrails_ai.types.FailResult¶
Bases:
guardrails_ai.types.validation_result.ValidationResultThe output of a validator when validation fails.
- classmethod deserialize_outcome(outcome: str | None) Literal[guardrails_ai.types.validation_result.Outcome.FAIL]¶
- error_spans: List[guardrails_ai.types.error_span.ErrorSpan] | None¶
- class guardrails_ai.types.Guard¶
Bases:
CreateGuardRequestA configured validation pipeline retrieved from the Guardrails API.
- model_config¶
- class guardrails_ai.types.JSONSchema¶
Bases:
pydantic.BaseModelA 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¶
- any_of: List[SchemaValue] | None¶
- contains: SchemaValue | None¶
- content_schema: SchemaValue | None¶
- definitions: Dict[str, SchemaValue] | None¶
- defs: Dict[str, SchemaValue] | None¶
- dependencies: Dict[str, SchemaValue | List[str]] | None¶
- dependent_schemas: Dict[str, SchemaValue] | None¶
- else_: SchemaValue | None¶
- if_: SchemaValue | None¶
- items: SchemaValue | None¶
- model_config¶
- not_: SchemaValue | None¶
- one_of: List[SchemaValue] | None¶
- pattern_properties: Dict[str, SchemaValue] | None¶
- prefix_items: List[SchemaValue] | None¶
- properties: Dict[str, SchemaValue] | None¶
- property_names: SchemaValue | None¶
- then: SchemaValue | None¶
- type: StringOrStringArray | None¶
- unevaluated_items: SchemaValue | None¶
- unevaluated_properties: SchemaValue | None¶
- class guardrails_ai.types.OnFail¶
-
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¶
-
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.ValidationResultPassResult 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¶
- class guardrails_ai.types.ReAsk¶
Bases:
pydantic.BaseModelRepresents a pending reask when validation fails and retries are exhausted.
- fail_results: List[guardrails_ai.types.fail_result.FailResult] | None¶
- model_config¶
- class guardrails_ai.types.ValidationOutcome¶
Bases:
pydantic.BaseModel,Generic[OT]The output from a Guard execution.
Type parameter
OTis bound tostr | List | Dictand reflects the shape ofvalidated_output.- model_config¶
- reask: guardrails_ai.types.reask.ReAsk | None¶
- validation_summaries: List[guardrails_ai.types.validation_summary.ValidationSummary] | None¶
- class guardrails_ai.types.ValidationResult¶
Bases:
pydantic.BaseModelValidationResult is the output type of Validator.validate and the abstract base class for all validation results.
- model_config¶
- class guardrails_ai.types.ValidationSummary¶
Bases:
pydantic.BaseModelPer-validator result produced during a Guard execution.
- error_spans: List[guardrails_ai.types.error_span.ErrorSpan] | None¶
- model_config¶
- validator_status: Literal['pass'] | Literal['fail']¶