The problem
As a concept, guardrailing has a few areas that, when unoptimized, can introduce latency and be extremely resource-expensive. The main two areas are:- Guardrailing orchestration; and
- ML models that validate a single guard
The Guardrails approach
The Guardrails library lets you separate the execution of orchestration from the execution of ML-based validation. Instead of running a validator’s ML model in the same process as your application, you can host that model behind an API and configure the validator to call that remote endpoint. The endpoint presents a unified interface that all validator models implement.Remote validation inferencing is available in Guardrails versions 0.5.0 and above.
Running a validator’s model locally (default)
By default, a validator runs its ML model in-process. Install the validator and use it directly:Hosting your own endpoint
For higher throughput — or to keep heavy ML models off your application hosts — run a validator’s model behind your own inference endpoint. Any endpoint that implements the interface Guardrails validators expect will work; that interface is defined in the_inference_remote method of the validator.
After implementing the interface, host it (for example, using gunicorn and Flask) and point the validator at it with the validation_endpoint constructor argument: