To download this example as a Jupyter notebook, click here.
Setup
In order to check semantic similarity we will need thenumpy package via the command below. We will also install the validators we intend to use.
Step 1: Load data and create Pydantic model
Load our text with the code below:Step 2: Create Guard from pydantic
The guard we create will:- Enforce reading time
- Enforce length
- Enforce similarity
Step 3: Call LLM via guard()
We use the tools API to ensure our data is returned in a structured form.
Guard object below:
guard wrapper returns the raw_llm_response (which is a simple string), and the validated and corrected output (which is a dictionary). We can see that the output is a dictionary with the correct schema and types.
Now let’s try a model that’s not as proficient at summarization and we can see the output is filtered and validation has failed.
The final validated output is None due to the failed validation.