Python Quick Start
Get started with the Autoblocks Testing SDK for Python.
Overview
Autoblocks Testing enables you to declaratively define tests for your LLM application and execute them either locally or in a CI/CD pipeline. Your tests can exist in a standalone script or be executed as part of a larger test framework.
Getting Started
Install the SDK
Define your test case schema
Your test case schema should contain all of the properties necessary to run your test function and to then make assertions on the output via your evaluators. This schema can be anything you want in order to facilitate testing your application.
Implement a function to test
This function should take an instance of a test case and return an output. The function can be synchronous or asynchronous and the output can be anything: a string, a number, a complex object, etc.
For this example, we are splitting the test case’s input
property on its hyphens and randomly discarding some of the substrings
to simulate failures on the has-all-substrings
evaluator.
Create an evaluator
Evaluators allow you to attach an Evaluation
to a test case’s output,
where the output is the result of running the test case through the function you are testing.
Your test suite can have multiple evaluators.
The evaluation method that you implement on the evaluator will have access to both the test case
instance and the output of the test function over the given test case. Your evaluation method
can be synchronous or asynchronous, but it must return an instance of Evaluation
.
The evaluation must have a score between 0 and 1, and you can optionally attach a
Threshold
that describes the range the score must be in in order
to be considered passing. If no threshold is attached, the score is reported and the pass / fail
status is undefined. Evaluations can also have metadata attached to them, which can be useful
for providing additional context when an evaluation fails.
For this example we’ll define two evaluators:
Create a test suite
We now have all of the pieces necessary to run a test suite. Below we’ll generate some toy test cases in the schema we defined above, where the input is a random UUID and its expected substrings are the substrings of the UUID when split by ”-“:
Run the test suite locally
To execute this test suite, first get your local testing API key from the settings page and set it as an environment variable:
Make sure you’ve followed our CLI setup instructions and then run the following:
The autoblocks testing exec
command will show the progress of all test suites in your terminal
and also send the results to Autoblocks:
You can view details of the results by clicking on the link displayed in the terminal or by visiting the test suites page in the Autoblocks platform.
Examples
To see a more complete example, check out our Python example repository.