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

# Legal Information Policies

> Protect case numbers and attorney-client privileged information

```bash theme={null}
# pip install "upsonic[safety-engine]"
uv pip install "upsonic[safety-engine]"
```

## What is Legal Info Policy?

Legal information policies detect and protect case numbers, legal IDs, court documents, attorney-client privileged information, and other sensitive legal data.

## Why its Important?

Legal information policies are essential for protecting attorney-client privilege, trade secrets, and confidential legal documents. These policies prevent sensitive legal information from being sent to LLMs, which helps maintain legal confidentiality and protects against privilege waivers.

* **Prevents sending legal documents to LLM**: Blocks case numbers, court documents, and attorney-client privileged information from being processed by language models
* **Protects attorney-client privilege**: Ensures confidential legal communications and privileged information are not exposed to third-party LLM providers
* **Maintains legal confidentiality**: Prevents trade secrets, settlement agreements, and sensitive business data from being processed or shared

## Anonymize (Unique Random Placeholders)

```python theme={null}
from upsonic import Agent, Task
from upsonic.safety_engine.policies import LegalInfoAnonymizePolicy

agent = Agent(
    "anthropic/claude-sonnet-4-6",
    user_policy=LegalInfoAnonymizePolicy,
    debug=True
)

task = Task("Case number 2024-CV-12345 involves attorney-client privileged information")
result = agent.print_do(task)
print(result)
```

## Replace (Fixed Placeholder)

```python theme={null}
from upsonic import Agent, Task
from upsonic.safety_engine.policies import LegalInfoReplacePolicy

agent = Agent(
    "anthropic/claude-sonnet-4-6",
    user_policy=LegalInfoReplacePolicy,
    debug=True
)

task = Task("Case number 2024-CV-12345 involves attorney-client privileged information")
result = agent.print_do(task)
print(result)
```

## Block

```python theme={null}
from upsonic import Agent, Task
from upsonic.safety_engine.policies import LegalInfoBlockPolicy

agent = Agent(
    "anthropic/claude-sonnet-4-6",
    user_policy=LegalInfoBlockPolicy,
    debug=True
)

task = Task("Case number 2024-CV-12345 involves attorney-client privileged information")
result = agent.print_do(task)
print(result)
```

## Available Variants

* `LegalInfoBlockPolicy`: Pattern detection with blocking
* `LegalInfoBlockPolicy_LLM`: LLM-powered block messages
* `LegalInfoBlockPolicy_LLM_Finder`: LLM detection for better accuracy
* `LegalInfoAnonymizePolicy`: Anonymizes legal data with unique random replacements
* `LegalInfoReplacePolicy`: Replaces with fixed placeholder
* `LegalInfoRaiseExceptionPolicy`: Raises DisallowedOperation exception
* `LegalInfoRaiseExceptionPolicy_LLM`: LLM-generated exception messages
