guardrails_ai.types =================== .. py:module:: guardrails_ai.types Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/guardrails_ai/types/error_span/index /autoapi/guardrails_ai/types/fail_result/index /autoapi/guardrails_ai/types/guard/index /autoapi/guardrails_ai/types/json_schema_2020_12/index /autoapi/guardrails_ai/types/on_fail/index /autoapi/guardrails_ai/types/pass_result/index /autoapi/guardrails_ai/types/reask/index /autoapi/guardrails_ai/types/validation_outcome/index /autoapi/guardrails_ai/types/validation_result/index /autoapi/guardrails_ai/types/validation_summary/index /autoapi/guardrails_ai/types/validator/index Classes ------- .. autoapisummary:: guardrails_ai.types.CreateGuardRequest guardrails_ai.types.ErrorSpan guardrails_ai.types.FailResult guardrails_ai.types.Guard guardrails_ai.types.JSONSchema guardrails_ai.types.OnFail guardrails_ai.types.Outcome guardrails_ai.types.PassResult guardrails_ai.types.ReAsk guardrails_ai.types.ValidationOutcome guardrails_ai.types.ValidationResult guardrails_ai.types.ValidationSummary guardrails_ai.types.Validator Package Contents ---------------- .. py:class:: CreateGuardRequest Bases: :py:obj:`pydantic.BaseModel` The required request body to created a Guard in the Guardrails API. .. py:attribute:: description :type: Optional[str] .. py:attribute:: model_config .. py:attribute:: name :type: str .. py:attribute:: output_schema :type: guardrails_ai.types.json_schema_2020_12.JSONSchema .. py:attribute:: validators :type: List[guardrails_ai.types.validator.Validator] .. py:class:: ErrorSpan Bases: :py:obj:`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. .. py:attribute:: end :type: int .. py:attribute:: model_config .. py:attribute:: reason :type: str .. py:attribute:: start :type: int .. py:class:: FailResult Bases: :py:obj:`guardrails_ai.types.validation_result.ValidationResult` The output of a validator when validation fails. .. py:method:: deserialize_outcome(outcome: str | None) -> Literal[guardrails_ai.types.validation_result.Outcome.FAIL] :classmethod: .. py:attribute:: error_message :type: str .. py:attribute:: error_spans :type: Optional[List[guardrails_ai.types.error_span.ErrorSpan]] .. py:attribute:: fix_value :type: Optional[Any] .. py:attribute:: outcome :type: guardrails_ai.types.validation_result.Outcome .. py:class:: Guard Bases: :py:obj:`CreateGuardRequest` A configured validation pipeline retrieved from the Guardrails API. .. py:attribute:: id :type: str .. py:attribute:: model_config .. py:class:: JSONSchema Bases: :py:obj:`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. .. py:method:: validate_conditional() -> JSONSchema Validate that then/else are only used with if. .. py:method:: validate_contains_constraints() -> JSONSchema Validate that minContains and maxContains are used with contains. .. py:method:: validate_length_constraints() -> JSONSchema Validate min/max length constraints. .. py:method:: validate_numeric_constraints() -> JSONSchema Validate numeric constraints. .. py:method:: validate_type(v: StringOrStringArray | None) -> StringOrStringArray | None :classmethod: Validate that type values are one of the allowed JSON Schema types. .. py:attribute:: additional_properties :type: SchemaValue | None .. py:attribute:: all_of :type: List[SchemaValue] | None .. py:attribute:: anchor :type: str | None .. py:attribute:: any_of :type: List[SchemaValue] | None .. py:attribute:: comment :type: str | None .. py:attribute:: const :type: Any | None .. py:attribute:: contains :type: SchemaValue | None .. py:attribute:: content_encoding :type: str | None .. py:attribute:: content_media_type :type: str | None .. py:attribute:: content_schema :type: SchemaValue | None .. py:attribute:: default :type: Any | None .. py:attribute:: definitions :type: Dict[str, SchemaValue] | None .. py:attribute:: defs :type: Dict[str, SchemaValue] | None .. py:attribute:: dependencies :type: Dict[str, Union[SchemaValue, List[str]]] | None .. py:attribute:: dependent_required :type: Dict[str, List[str]] | None .. py:attribute:: dependent_schemas :type: Dict[str, SchemaValue] | None .. py:attribute:: deprecated :type: bool | None .. py:attribute:: description :type: str | None .. py:attribute:: dynamic_anchor :type: str | None .. py:attribute:: dynamic_ref :type: str | None .. py:attribute:: else_ :type: SchemaValue | None .. py:attribute:: enum :type: List[Any] | None .. py:attribute:: examples :type: List[Any] | None .. py:attribute:: exclusive_maximum :type: float | int | None .. py:attribute:: exclusive_minimum :type: float | int | None .. py:attribute:: format :type: str | None .. py:attribute:: id :type: str | None .. py:attribute:: if_ :type: SchemaValue | None .. py:attribute:: items :type: SchemaValue | None .. py:attribute:: max_contains :type: int | None .. py:attribute:: max_items :type: int | None .. py:attribute:: max_length :type: int | None .. py:attribute:: max_properties :type: int | None .. py:attribute:: maximum :type: float | int | None .. py:attribute:: min_contains :type: int | None .. py:attribute:: min_items :type: int | None .. py:attribute:: min_length :type: int | None .. py:attribute:: min_properties :type: int | None .. py:attribute:: minimum :type: float | int | None .. py:attribute:: model_config .. py:attribute:: multiple_of :type: float | int | None .. py:attribute:: not_ :type: SchemaValue | None .. py:attribute:: one_of :type: List[SchemaValue] | None .. py:attribute:: pattern :type: str | None .. py:attribute:: pattern_properties :type: Dict[str, SchemaValue] | None .. py:attribute:: prefix_items :type: List[SchemaValue] | None .. py:attribute:: properties :type: Dict[str, SchemaValue] | None .. py:attribute:: property_names :type: SchemaValue | None .. py:attribute:: read_only :type: bool | None .. py:attribute:: recursive_anchor :type: bool | None .. py:attribute:: recursive_ref :type: str | None .. py:attribute:: ref :type: str | None .. py:attribute:: required :type: List[str] | None .. py:attribute:: schema_ :type: str | None .. py:attribute:: then :type: SchemaValue | None .. py:attribute:: title :type: str | None .. py:attribute:: type :type: StringOrStringArray | None .. py:attribute:: unevaluated_items :type: SchemaValue | None .. py:attribute:: unevaluated_properties :type: SchemaValue | None .. py:attribute:: unique_items :type: bool | None .. py:attribute:: vocabulary :type: Dict[str, bool] | None .. py:attribute:: write_only :type: bool | None .. py:class:: OnFail Bases: :py:obj:`str`, :py:obj:`enum.Enum` OnFail is an Enum that represents the different actions that can be taken when a validation fails. .. attribute:: REASK On failure, Reask the LLM. :type: Literal["reask"] .. attribute:: FIX On failure, apply a static fix. :type: Literal["fix"] .. attribute:: FILTER On failure, filter out the invalid values. :type: Literal["filter"] .. attribute:: REFRAIN On failure, refrain from responding; return an empty value. :type: Literal["refrain"] .. attribute:: NOOP On failure, do nothing. :type: Literal["noop"] .. attribute:: EXCEPTION On failure, raise a ValidationError. :type: Literal["exception"] .. attribute:: 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"] .. attribute:: 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. .. py:attribute:: CUSTOM :value: 'custom' .. py:attribute:: EXCEPTION :value: 'exception' .. py:attribute:: FILTER :value: 'filter' .. py:attribute:: FIX :value: 'fix' .. py:attribute:: FIX_REASK :value: 'fix_reask' .. py:attribute:: NOOP :value: 'noop' .. py:attribute:: REASK :value: 'reask' .. py:attribute:: REFRAIN :value: 'refrain' .. py:class:: Outcome Bases: :py:obj:`str`, :py:obj:`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. .. py:attribute:: FAIL :value: 'fail' .. py:attribute:: PASS :value: 'pass' .. py:class:: PassResult Bases: :py:obj:`guardrails_ai.types.validation_result.ValidationResult` PassResult is the output type of Validator.validate when validation succeeds. .. py:class:: ValueOverrideSentinel .. py:method:: deserialize_outcome(outcome: str | None) -> Literal[guardrails_ai.types.validation_result.Outcome.PASS] :classmethod: .. py:method:: deserialize_value_override(value_override: Any | None) -> ValueOverrideSentinel | Any | None :classmethod: .. py:method:: serialize_value_override(value_override: Any | None) -> Any | None .. py:attribute:: outcome :type: guardrails_ai.types.validation_result.Outcome .. py:attribute:: value_override :type: Optional[Any] .. py:class:: ReAsk Bases: :py:obj:`pydantic.BaseModel` Represents a pending reask when validation fails and retries are exhausted. .. py:attribute:: fail_results :type: Optional[List[guardrails_ai.types.fail_result.FailResult]] .. py:attribute:: incorrect_value :type: Optional[Any] .. py:attribute:: model_config .. py:class:: ValidationOutcome Bases: :py:obj:`pydantic.BaseModel`, :py:obj:`Generic`\ [\ :py:obj:`OT`\ ] The output from a Guard execution. Type parameter ``OT`` is bound to ``str | List | Dict`` and reflects the shape of ``validated_output``. .. py:attribute:: call_id :type: str .. py:attribute:: error :type: Optional[str] .. py:attribute:: model_config .. py:attribute:: raw_llm_output :type: Optional[str] .. py:attribute:: reask :type: Optional[guardrails_ai.types.reask.ReAsk] .. py:attribute:: validated_output :type: Optional[OT] .. py:attribute:: validation_passed :type: Optional[bool] .. py:attribute:: validation_summaries :type: Optional[List[guardrails_ai.types.validation_summary.ValidationSummary]] .. py:class:: ValidationResult Bases: :py:obj:`pydantic.BaseModel` ValidationResult is the output type of Validator.validate and the abstract base class for all validation results. .. py:attribute:: metadata :type: Optional[Dict[str, Any]] .. py:attribute:: model_config .. py:attribute:: outcome :type: Outcome .. py:attribute:: validated_chunk :type: Optional[Any] .. py:class:: ValidationSummary Bases: :py:obj:`pydantic.BaseModel` Per-validator result produced during a Guard execution. .. py:attribute:: error_spans :type: Optional[List[guardrails_ai.types.error_span.ErrorSpan]] .. py:attribute:: failure_reason :type: Optional[str] .. py:attribute:: model_config .. py:attribute:: property_path :type: Optional[str] .. py:attribute:: validator_name :type: str .. py:attribute:: validator_status :type: Literal['pass'] | Literal['fail'] .. py:class:: Validator Bases: :py:obj:`pydantic.BaseModel` A validator attached to a Guard, including its configuration. .. py:attribute:: args :type: Optional[List[Any]] :value: None .. py:attribute:: id :type: str .. py:attribute:: kwargs :type: Dict[str, Any] .. py:attribute:: model_config .. py:attribute:: on :type: Optional[str] .. py:attribute:: on_fail :type: Optional[guardrails_ai.types.on_fail.OnFail]