Skip to main content

nemoguardrails-redefiner

PII detection and masking rails for NVIDIA NeMo Guardrails, using ReDefiNER: an open model (0.8B parameters, Apache 2.0) that finds what a rulebook written in plain English defines. The model runs inside your NeMo Guardrails process on CPU or GPU, so no text leaves your machine and there is no server to run. English only.

  • redefiner local mask pii on input|output|retrieval: replaces personal data with its type in brackets, e.g. Hi, I am [PERSON]. Email me at [EMAIL].
  • redefiner local detect pii on input|output|retrieval: blocks the message instead.

By default the PII rulebook of jungroo-ai/redefiner-pii is used, with 20 types: PERSON, TITLE, USERNAME, EMAIL, PHONE, ADDRESS, LOCATION, COORDINATE, ORGANIZATION, OCCUPATION, DATE_TIME, AGE, GENDER, DEMOGRAPHIC, GOVERNMENT_ID, ID_NUMBER, IP_ADDRESS, URL, FINANCIAL and SECRET. Set your own rulebook to decide what counts as personal data for your application.

This package is maintained by Jungroo AI Labs. It is not part of NeMo Guardrails.

Install

pip install nemoguardrails-redefiner

It needs nemoguardrails 0.25 or later and Python 3.11 or later. The first message downloads the model weights (about 0.8 GB) from Hugging Face.

Set up a config folder

Add the flows and actions to your NeMo Guardrails config folder:

python -m nemoguardrails_redefiner init config/
# wrote config/redefiner.co (Colang 1.0)
# wrote config/config.py

redefiner.co defines the six flows. config.py registers the two actions:

from nemoguardrails_redefiner import register


def init(app):
    register(app)

If your folder already has a config.py, init leaves it alone and prints the two lines to add. It never overwrites a file. For a Colang 2.x config, pass --colang 2.x.

Then turn the flows on in config.yml:

rails:
  input:
    flows:
      - redefiner local mask pii on input
  output:
    flows:
      - redefiner local mask pii on output
from nemoguardrails import Guardrails, RailsConfig
from nemoguardrails.rails.llm.options import RailType

rails = Guardrails(RailsConfig.from_path("config"))
result = rails.check(
    [{"role": "user", "content": "Hi, I am Maria Okafor. Email me at maria.okafor@acme.com or call +1 415 555 0134."}],
    rail_types=[RailType.INPUT],
)
print(result.content)
# Hi, I am [PERSON]. Email me at [EMAIL] or call [PHONE].

Your own rulebook

Settings go under custom_data.redefiner in config.yml. A rulebook defines each type in plain English, and a [TYPE] NOT_AN_ENTITY section says what must not be extracted:

custom_data:
  redefiner:
    rulebook: |
      [RULES]
      G1 Extract every piece of personal data of the supplied types. Return exact spans from the text.

      [TYPE] PERSON
      [DESCRIPTION] A person's name, without titles such as "Dr." or "Ms".

      [TYPE] EMPLOYEE_ID
      [DESCRIPTION] An employee number, such as "E-48213".

      [TYPE] SALARY
      [DESCRIPTION] A person's pay: salary, bonus or hourly rate, with its currency.

      [TYPE] NOT_AN_ENTITY
      NE1 Names of teams, departments and products, and the company's own name.

rails:
  input:
    flows:
      - redefiner local mask pii on input

Dr. Maria Okafor (E-40917) joins the Payments team at Acme on a salary of $96,500. becomes Dr. [PERSON] ([EMPLOYEE_ID]) joins the Payments team at Acme on a salary of [SALARY]. The rulebook can also be a path to a file, relative to the config folder (rulebook: rules/pii.txt). For how to write rules, see the ReDefiNER rulebook guide.

Settings

All settings are optional.

Setting Default Meaning
model jungroo-ai/redefiner-pii A Hugging Face repo or local folder
rulebook the model's default Rulebook text, or a path to a rulebook file
input.entities, output.entities, retrieval.entities all types Only these rulebook types block or are masked on that source, e.g. [PERSON, EMAIL]. With your own rulebook, a type it does not define is an error.
min_confidence 0.0 Ignore spans below this confidence
threshold, none_bias, max_span_tokens model defaults ReDefiNER settings; see its README
device GPU if available cpu, cuda or cuda:N
revision latest A Hugging Face revision of the model
preload false Load the model when the config loads, not on the first message
custom_data:
  redefiner:
    preload: true
    output:
      entities: [PERSON, PHONE, EMAIL]

How it behaves

  • Fails closed. If the model can't load or raises, the action raises too, and NeMo Guardrails answers with its internal-error message (blocked from check) instead of passing the text on unchecked. A misconfigured custom_data.redefiner raises the same way, with the setting's name in the error.
  • Speed. The first message loads the model and reads the rulebook: about 20 seconds on a laptop CPU in our test. Later messages took about 0.6 seconds each for a sentence. Set preload: true to load the model at start-up.
  • One model per process. Every config that uses the same model, device and settings shares one loaded copy, and calls to it run one at a time.
  • What is logged. The actions log nothing. Their outcome metadata holds the types found and the span count, never the text.
  • Colang. Both Colang 1.0 and 2.x configs work, through the LLMRails engine. Colang 2.x is deprecated as of NeMo Guardrails 0.25. With Colang 2.x, a failure ends the turn without a reply.

Limitations

  • English only.
  • The model can miss personal data, and accuracy depends on the rulebook. Check it on your own conversations, and don't rely on it alone.
  • Overlapping spans are merged into one placeholder that uses the first span's type.

License

Apache 2.0. ReDefiNER's weights are Apache 2.0 too.

Metadata

Release files for nemoguardrails-redefiner 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nemoguardrails-redefiner 0.1.0
File Size Uploaded Provenance Actions
nemoguardrails_redefiner-0.1.0.tar.gz 19.6 kB Without provenance Details for nemoguardrails_redefiner-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nemoguardrails-redefiner 0.1.0
File Interpreter ABI Platform Actions
nemoguardrails_redefiner-0.1.0-py3-none-any.whl Python 3 none any Details for nemoguardrails_redefiner-0.1.0-py3-none-any.whl

Total release size: 35.4 kB

Release files / nemoguardrails_redefiner-0.1.0.tar.gz

Download URL nemoguardrails_redefiner-0.1.0.tar.gz
Size 19.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b35862ab50647d6073d3ebdc255860352399a68c7ff293cdf721f45b25a167e6
BLAKE2b-256 checksum
How to use checksums
f9e60267b781a139940fe455a717a1816f933e1ea6febe344dfe6d0b63876703
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / nemoguardrails_redefiner-0.1.0-py3-none-any.whl

Download URL nemoguardrails_redefiner-0.1.0-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d351ad25ed798c8aef9327a5bc25f3ca9abe53bc7dc8cedc655f3c0bbc9d296f
BLAKE2b-256 checksum
How to use checksums
7b4183f06d814228f86c173d27b77046fd74528e97914d2acf1ea79b5fbc3bde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for nemoguardrails-redefiner 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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page