# DataFog

> Detect and redact PII from text before it reaches your LLM

- Category: Evaluation & Production Ops / Guardrails & Security
- Language: Python
- Repository: https://github.com/DataFog/datafog-python
- Website: https://datafog.ai
- Canonical page: https://ai-tldr.dev/tools/datafog/

## In short

DataFog is a Python library for detecting and redacting personally identifiable information (PII). It sits in the Guardrails & Security category of the Evaluation & Production Ops tools and is open-source, written in Python. To get started: install DataFog.

## Overview

DataFog is a Python library for detecting and redacting personally identifiable information (PII). The core install ships a fast regex engine that finds structured entities like emails, phone numbers, SSNs, credit cards, and IP addresses, and you can add NLP, OCR, or Spark support as optional extras only when you need them.

It is aimed at teams building LLM applications who want to scrub user prompts and model output before that data leaves their control. The library exposes simple helpers such as `sanitize`, `scan_prompt`, and `filter_output`, plus a reusable guardrail decorator you can wrap around any function that calls a model.

As a PII and security tool, DataFog sits in front of your LLM calls. The default regex engine is always available and needs no extra dependencies, while the `spacy`, `gliner`, and `smart` engines trade more setup for stronger coverage of unstructured names and organizations.

## What it does

- Fast structured PII detection via regex for emails, phones, SSNs, credit cards, IP addresses, dates, and ZIP codes
- Optional NER engines (spaCy and GLiNER) for unstructured entities like person and organization names
- A `smart` engine that cascades regex with optional NER and degrades gracefully when those deps are missing
- LLM-focused helpers: `scan_prompt`, `filter_output`, `sanitize`, and a reusable `create_guardrail` decorator
- Opt-in German structured PII via `locales=["de"]` for VAT IDs, IBANs, tax IDs, postal codes, and more
- A CLI for scanning, redacting, pseudonymizing, and hashing text, plus optional OCR and Spark surfaces

## Getting started

Install the core package and redact PII from text in a few lines. The default regex engine needs no extra dependencies.

1. Install DataFog

   Install the core package with the regex engine. Optional extras add spaCy, GLiNER, OCR, or Spark support.

```bash
pip install datafog
```

2. Redact PII in one line

   Use `sanitize` with the regex engine to replace detected PII with typed placeholders.

```python
import datafog

text = "Contact john@example.com or call (555) 123-4567"
clean = datafog.sanitize(text, engine="regex")
print(clean)
# Contact [EMAIL_1] or call [PHONE_1]
```

3. Guard an LLM call

   Scan prompts before sending them and redact model output before returning it, or wrap a function with a reusable guardrail.

```python
import datafog

# Scan a prompt before sending it to an LLM
scan_result = datafog.scan_prompt("My SSN is 123-45-6789", engine="regex")
if scan_result.entities:
    print(f"Detected {len(scan_result.entities)} PII entities")

# Redact model output before returning it
safe = datafog.filter_output("Email me at jane.doe@example.com", engine="regex")
print(safe.redacted_text)
# Email me at [EMAIL_1]
```

4. Try the CLI

   Scan, redact, pseudonymize, or hash text straight from the terminal.

```bash
datafog redact-text "john@example.com"
```

## When to use it

- Strip emails, phone numbers, and SSNs out of user prompts before sending them to an LLM API
- Redact model output so PII never leaks back to the end user
- Wrap LLM-calling functions in a reusable guardrail decorator to enforce redaction in one place
- Scan or hash PII in batch text with the CLI, or scale detection over large datasets with the Spark extra
