← Journal
Verify LLM Output Before Trusting It: Running Guardrails AI

Verify LLM Output Before Trusting It: Running Guardrails AI

A record of running Guardrails AI with the network blocked while validating LLM output against a schema. We tested eight ways to break the schema to assess validation granularity and found that the default configuration also tries to send telemetry to an external endpoint.

Repository covered in this article

guardrails-ai/guardrails

Adding guardrails to large language models.

7.2k Python Apache License 2.0

A system can accept out-of-range values and unexpected formats when you feed it LLM output. Guardrails AI validates LLM output or any text against a schema and determines whether it passes. I installed it and tested whether validation worked with the network blocked.

Guardrails AI checks text against schemas defined with Pydantic models and similar tools. You can use it to validate existing output without calling an LLM. The source code is available under the Apache 2.0 License (*1).

1. Install Guardrails AI

FROM docker.io/library/python:3.12.13-slim
RUN pip install --no-cache-dir --quiet 'guardrails-ai==0.10.2'
WORKDIR /work
podman build -t guardrails-ai-sandbox .

2. Test validation granularity with eight ways to break the schema

We skipped LLM calls and passed eight JSON strings to the validator, covering different ways to break the schema. Along with the pass/fail result, we checked whether the program could report which field failed and why. We ran the test with the network blocked.

from pydantic import BaseModel, Field
from guardrails import Guard

class IncidentReport(BaseModel):
    severity: str = Field(json_schema_extra={"enum": ["low", "medium", "high"]})
    downtime_minutes: int = Field(ge=0, le=1440)

guard = Guard.for_pydantic(IncidentReport)

cases = [
    ("valid input",    '{"severity": "high", "downtime_minutes": 12}'),
    ("enum violation", '{"severity": "catastrophic", "downtime_minutes": 12}'),
    ("over maximum",   '{"severity": "high", "downtime_minutes": 99999}'),
    ("under minimum",  '{"severity": "high", "downtime_minutes": -5}'),
    ("wrong type",     '{"severity": "high", "downtime_minutes": "twelve"}'),
    ("missing field",  '{"severity": "high"}'),
    ("extra field",    '{"severity": "high", "downtime_minutes": 12, "note": "x"}'),
    ("malformed JSON", '{"severity": "high", "downtime_minutes":'),
]

for label, output in cases:
    result = guard.parse(output)
    print(label, result.validation_passed)
    # failure reasons are available at result.reask.fail_results[].error_message
podman run --rm --network none --memory 2g --cpus 2 --pids-limit 512 \
  -v "$(pwd)":/work -w /work guardrails-ai-sandbox \
  python validate_matrix_demo.py

-v makes the specified directory available for reads and writes inside the container. Run the command from an empty directory dedicated to the experiment.

The command produced the following result.

valid input     passed=True
enum violation  passed=False  "$.severity": "'catastrophic' is not one of ['low', 'medium', 'high']"
over maximum    passed=False  "$.downtime_minutes": "99999 is greater than the maximum of 1440"
under minimum   passed=False  "$.downtime_minutes": "-5 is less than the minimum of 0"
wrong type      passed=False  "$.downtime_minutes": "'twelve' is not of type 'integer'"
missing field   passed=False  "$": "'downtime_minutes' is a required property"
extra field     passed=True
malformed JSON  passed=False  Output is not parseable as JSON

The result shows three things. First, the validator rejected all six failure cases: enum, upper-bound, lower-bound, type, required-field, and JSON-syntax violations. Second, result.reask.fail_results exposes the field, constraint, and offending value in machine-readable form. Downstream code can branch on the failure reason and the True/False result, prompting a new generation or filling in a default. It can route the case to a person. Third, **outputs with extra fields passed validation**. Pydantic ignores unknown fields by default, so you need an additional setting such as model_config = ConfigDict(extra="forbid") on the Pydantic model if you want to reject fields outside the schema. Validation does not make a system safe by itself. Check which inputs the default settings let through.

Trouble spot: Default telemetry export targets an external endpoint

The run printed the following warning more than once.

WARNING:opentelemetry.exporter.otlp.proto.http.trace_exporter:Transient error
HTTPSConnectionPool(host='hty0gc1ok3.execute-api.us-east-1.amazonaws.com', port=443):
Max retries exceeded with url: /v1/traces (Caused by NameResolutionError(...))

Guardrails AI's default configuration tries to send execution trace data through OpenTelemetry to an AWS endpoint. The --network none setting caused the connection to fail with a name-resolution error, so the process sent no telemetry outside the environment. The validator completed regardless of the telemetry export result, and the failed export did not affect validation.

An external telemetry service can be a sound design choice. Without network isolation, I could have run an unfamiliar tool without noticing this connection. The blocked run demonstrated why you should isolate an unfamiliar tool from the network.

Make validation a prerequisite

Place schema validation between LLM output and the system. That check can catch unexpected values before they enter the system. Test the execution environment, including the tool's network behavior. That scrutiny supports the reliability of the validation process.

Sources

*1 Guardrails AI (GitHub), https://github.com/guardrails-ai/guardrails, Apache 2.0 License