> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rehydra.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Anonymization & Pseudonymization

> Understand Rehydra's two protection modes and the shared processing model

Rehydra supports two closely related ways to protect sensitive text: `pseudonymize` for reversible workflows and `anonymize` for irreversible ones.

## The Two Modes

| Mode           | What happens                                                                               | Can you restore originals later? | Typical use                                             |
| -------------- | ------------------------------------------------------------------------------------------ | -------------------------------- | ------------------------------------------------------- |
| `pseudonymize` | Rehydra replaces detected values with placeholders and returns an encrypted `piiMap`       | Yes                              | Apps, agents, and workflows that need later rehydration |
| `anonymize`    | Rehydra replaces detected values with placeholders and discards the original-value mapping | No                               | One-way redaction and irreversible sharing              |

```typescript theme={null}
import { createAnonymizer } from 'rehydra';

const reversible = createAnonymizer({ mode: 'pseudonymize' });
const irreversible = createAnonymizer({ mode: 'anonymize' });
```

## Shared Processing Model

Both modes use the same high-level flow:

<Steps>
  <Step title="Detect">
    Rehydra runs enabled recognizers and optional NER to identify sensitive spans.
  </Step>

  <Step title="Resolve">
    Overlaps are resolved using type priority and confidence rules.
  </Step>

  <Step title="Replace">
    Original values are swapped for stable `<PII .../>` placeholders.
  </Step>

  <Step title="Store or discard">
    In `pseudonymize` mode Rehydra encrypts the mapping; in `anonymize` mode it does not keep one.
  </Step>
</Steps>

## Placeholder Output

Rehydra uses XML-like placeholders so downstream systems can safely process the text while preserving structure.

```xml theme={null}
<PII type="EMAIL" id="1"/>
<PII type="PERSON" id="1"/>
```

When semantic enrichment is enabled, placeholders can include extra attributes:

```xml theme={null}
<PII type="PERSON" gender="female" id="1"/>
<PII type="LOCATION" scope="city" id="2"/>
```

## Choosing the Right Mode

Use `pseudonymize` when:

* You need to restore the original values later
* You are building an application flow around rehydration
* You want encrypted mappings for sessions or agent workflows

Use `anonymize` when:

* You want irreversible protection
* You are preparing text for one-way sharing or analysis
* You do not want to manage keys or stored mappings

## Related Concepts

`pseudonymize` naturally connects to rehydration, encryption, and key management. `anonymize` is simpler, but it still depends on the same recognizers, type system, and configuration model.

## Next Steps

<CardGroup cols={2}>
  <Card title="Rehydration" icon="rotate-left" href="/concepts/rehydration">
    Learn how reversible workflows restore original values.
  </Card>

  <Card title="Configuration" icon="sliders" href="/concepts/configuration">
    See which settings shape detection and output behavior.
  </Card>
</CardGroup>
