drex-policy
A Guardrails validator that asks Drex, Nace.AI's decision model, one question about a string.
| Developed by | Nace.AI |
|---|---|
| Date of development | Oct 29, 2026 |
| Validator type | Moderation, policy |
| License | MIT |
| Input/Output | Input, Output |
What it checks
DrexPolicy asks Drex one question about a string and fails when the answer crosses a threshold you set. Use it for checks such as PII present, off-topic, toxicity level, jailbreak attempt, or competitor mention.
The question is a nace_sdk.Noul (probability of a yes answer) or a nace_sdk.Score (expected index over criteria you list). Drex returns the probability. You choose the threshold with fail_at, preferably from labeled examples from your application.
- Noul: fails when P(yes) is at or above
fail_at. Withfail_when="no", fails when P(yes) is belowfail_at. - Score: fails when the score is at or above
fail_at. Withfail_when="below", fails when the score is belowfail_at.
The Drex answer is in the result metadata on pass and on fail.
Models
The default model is drex-v2.0. Text-only checks can use any Drex model id, which is sent unchanged. drex-latest is sent as drex-latest. It is not drex-max.
To check images with the text, pass model="drex-max" and put the images in metadata["images"]. Each image is a URL or a data URL (PNG, JPEG, or WebP). drex-max accepts at most 8 images. If images are present and the model is not drex-max, or there are more than 8 images, the validator raises DrexPolicyError before it calls Drex. It does not drop the images.
Requirements
-
Dependencies:
- guardrails-ai>=0.4.0
- nace-sdk>=0.6.2
-
Access keys:
NACE_API_KEY: a key from console.nace.aiNACE_BASE_URL(optional): defaults tohttps://console.nace.ai
When the validator builds its own client, each HTTP attempt times out after 60 seconds, the total retry budget is 180 seconds, and requests carry X-Nace-Client: drex-policy/0.1.0.
Install
$ guardrails hub install hub://nace/drex_policy
You can also install the package from PyPI:
$ pip install drex-policy
With a PyPI install, import the validator from drex_policy instead of guardrails.hub:
from drex_policy import DrexPolicy
The examples below use the hub import. The class and its arguments are the same.
Examples
Check a string
from guardrails import Guard
from guardrails.hub import DrexPolicy
from nace_sdk import Noul
guard = Guard().use(
DrexPolicy(
question=Noul(instructions="Does the text contain a personal phone number or email address?"),
fail_at=0.5,
on_fail="exception",
)
)
guard.validate("Our office opens at 9am.") # Validator passes
guard.validate("Call me on +1 415 555 0100.") # Validator fails
Check text with images
from guardrails import Guard
from guardrails.hub import DrexPolicy
from nace_sdk import Score
guard = Guard().use(
DrexPolicy(
question=Score(
instructions="How unsafe is this listing for a general audience?",
criteria=["safe", "borderline", "unsafe"],
),
fail_at=1.5,
model="drex-max",
on_fail="exception",
)
)
guard.validate(
"Vintage camera, works well.",
metadata={"images": ["https://example.com/listing.jpg"]},
)
Check one field of structured output
from pydantic import BaseModel, Field
from guardrails import Guard
from guardrails.hub import DrexPolicy
from nace_sdk import Noul
off_topic = DrexPolicy(
question=Noul(instructions="Is this reply about something other than our billing product?"),
fail_at=0.5,
on_fail="exception",
)
class Reply(BaseModel):
answer: str = Field(validators=[off_topic])
guard = Guard.for_pydantic(output_class=Reply)
guard.parse('{"answer": "Your invoice is in Settings > Billing."}')
API reference
__init__(self, question, fail_at, fail_when=None, question_id="policy", model=None, client=None, on_fail=None)
question(nace_sdk.Noul | nace_sdk.Score): The question Drex answers about the value. Ifinstructionsis omitted, it staysNoneand is not sent.fail_at(float): For a noul, a P(yes) threshold between 0 and 1. For a score, a finite expected-index threshold.fail_when(str):"yes"(default) or"no"for a noul."at_or_above"(default) or"below"for a score.question_id(str): Key of the question in the Drex request and response. Default"policy".model(str): Drex model id. Defaultdrex-v2.0. Images needdrex-max.client(nace_sdk.NaceClient): An existing client. If omitted, the validator builds one that readsNACE_API_KEYandNACE_BASE_URL.on_fail(str, Callable): What Guardrails does on a fail: one ofexception,noop,reask,fix,filter,refrainorfix_reask, or a function that Guardrails calls on a fail.
Parameters
validate(self, value, metadata) -> ValidationResult
-
Asks Drex the question about `value` and compares the answer with `fail_at`. Do not call it directly. `guard.parse(...)` and `guard.validate(...)` call it.
-
value(str): The text to check. -
metadata(dict): Optional.Key Type Description Default imageslist[str] Image URLs or data URLs. Needs model="drex-max"; at most 8.None
If Drex cannot answer (a network error, an API error, or a response without the expected answer), the exception propagates. The validator does not turn it into a pass or a fail.
Parameters
Result metadata
| Key | Description |
|---|---|
drex_model |
Model id sent to Drex |
drex_question_id |
The question_id |
drex_answer |
The Drex answer, for example {"type": "noul", "noul": 0.93} |
License
MIT. Copyright (c) 2026 Nace.AI. See LICENSE.
Scaffolding from guardrails-ai/validator-template (Apache-2.0).
Metadata
Release files for drex-policy 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| drex_policy-0.1.0.tar.gz | 8.1 kB | With provenance | Details for drex_policy-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| drex_policy-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for drex_policy-0.1.0-py3-none-any.whl |
Total release size: 15.2 kB
Release files / drex_policy-0.1.0.tar.gz
| Download URL | drex_policy-0.1.0.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4e9bab3562bf972d47a629740fdb5176975e03c66f33b3ad2f3ac3bd587fa50a
|
|
BLAKE2b-256 checksum How to use checksums |
713d803998fb9649890d6e16c03a19a71a92ef9c11c62c2ec5f39a01769b2497
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logRelease files / drex_policy-0.1.0-py3-none-any.whl
| Download URL | drex_policy-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c131518ef41f49145bb0edd96a2a628cc036c008c887278f2cee5fc0ac7b4a88
|
|
BLAKE2b-256 checksum How to use checksums |
3e32bb65235aa07c439d5ac791a118fbad7321b8c98dcd226a640f9e8a4645bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logSecurity for drex-policy 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for drex_policy-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.