|
3 | 3 | Validators are how we apply quality controls to the schemas specified in our `RAIL` specs. They specify the criteria to measure whether an output is valid, as well as what actions to take when an output does not meet those criteria. |
4 | 4 |
|
5 | 5 | ## How do Validators work? |
6 | | -When a validator is applied to a property on a schema, and output is provided for that schema, either by wrapping the LLM call or passing in the LLM output, the validators are executed against the values for the properties they were applied to. If the value for the property passes the criteria defined, a `PassResult` is returned from the validator. This `PassResult` tells Guardrails to treat the value as if it is valid. In most cases this means returning that value for that property at the end; other advanced cases, like using a value override, will be covered in other sections. If, however, the value for the property does not pass the criteria, a `FailResult` is returned. This in turn tells Guardrails to take any corrective actions defined for the property and validation. Corrective actions are defined by the `on-fail-...` attributes in a `RAIL` spec. You can read more about what corrective actions are available [here](/concepts/output/#specifying-corrective-actions). |
| 6 | +When a validator is applied to a property on a schema, and output is provided for that schema, either by wrapping the LLM call or passing in the LLM output, the validators are executed against the values for the properties they were applied to. If the value for the property passes the criteria defined, a `PassResult` is returned from the validator. This `PassResult` tells Guardrails to treat the value as if it is valid. In most cases this means returning that value for that property at the end; other advanced cases, like using a value override, will be covered in other sections. If, however, the value for the property does not pass the criteria, a `FailResult` is returned. This in turn tells Guardrails to take any corrective actions defined for the property and validation. Corrective actions are defined by the `on-fail-...` attributes in a `RAIL` spec. You can read more about what corrective actions are available [here](/docs/concepts/output#%EF%B8%8F-specifying-corrective-actions). |
7 | 7 |
|
8 | 8 | ## Validator Structure |
9 | 9 | ### Arguments |
@@ -49,14 +49,14 @@ raw_output, guarded_output, *rest = guard( |
49 | 49 | ``` |
50 | 50 |
|
51 | 51 | #### How do I know what metadata is required? |
52 | | -First step is to check the docs. Each validator has an API reference that documents both its initialization arguments and any required metadata that must be supplied at runtime. Continuing with the example used above, `ExtractedSummarySentencesMatch` accepts an optional threshold argument which defaults to `0.7`; it also requires an entry in the metadata called `filepaths` which is an array of strings specifying which documents to use for the similarity comparison. You can see an example of a Validator's metadata documentation [here](../api_reference/validators.md/#guardrails.validators.ExtractedSummarySentencesMatch). |
| 52 | +First step is to check the docs. Each validator has an API reference that documents both its initialization arguments and any required metadata that must be supplied at runtime. Continuing with the example used above, `ExtractedSummarySentencesMatch` accepts an optional threshold argument which defaults to `0.7`; it also requires an entry in the metadata called `filepaths` which is an array of strings specifying which documents to use for the similarity comparison. You can see an example of a Validator's metadata documentation [here](/docs/api_reference_markdown/validators#extractedsummarysentencesmatch). |
53 | 53 |
|
54 | 54 | Secondly, if a piece of metadata is required and not present, a `RuntimeError` will be raised. For example, if the metadata requirements are not met for the above validator, an `RuntimeError` will be raised with the following message: |
55 | 55 |
|
56 | 56 | > extracted-sentences-summary-match validator expects `filepaths` key in metadata |
57 | 57 |
|
58 | 58 | ## Custom Validators |
59 | | -If you need to perform a validation that is not currently supported by the [validators](../api_reference/validators.md) included in guardrails, you can create your own custom validators to be used in your local python environment. |
| 59 | +If you need to perform a validation that is not currently supported by the [validators](/docs/api_reference_markdown/validators) included in guardrails, you can create your own custom validators to be used in your local python environment. |
60 | 60 |
|
61 | 61 | A custom validator can be as simple as a single function if you do not require addtional arguments: |
62 | 62 | ```py |
|
0 commit comments