Skip to content

Documentation navigation

Private Data and PII

Redact sensitive data, understand what leaves your machine, and manage private-value restoration.

Privacy control, not certification

mAIvn holds no SOC 2, HIPAA, ISO 27001, or FedRAMP certification. The Platform Disclaimer explains what these controls do not cover.

#Private Data and PII Protection

The SDK has controls designed to keep secrets and personal data out of model-visible context. This guide shows how to configure them and where they stop.

Redaction aids, not compliance. phi_mode and HIPAA_SAFE_HARBOR_CATEGORIES are redaction aids. Using them does not make a deployment compliant with health-privacy law, and the hosted Service does not accept protected health information without a separate signed agreement; see the Acceptable Use Policy. mAIvn holds no SOC 2, HIPAA, ISO 27001, or FedRAMP certification, and cannot guarantee that every private value is detected. These controls do not replace required audits and organizational safeguards.

#When these controls apply

Declare sensitive values with private_data or send RedactedMessage to request automatic detection. Plain strings, HumanMessage and unmarked public decision text receive no automatic redaction, placeholders or privacy refusals solely because the text resembles personal data.

DecisionRequest.private_data marks known values for platform shielding. Private/unknown requests keep their fallback. Each decision checks its own request; it does not export a surrounding private context automatically. See Decisions.

#Why it matters

Two kinds of sensitive data tend to flow toward the model:

  • Your secrets: API keys, database passwords and signing tokens that your tools need.
  • Your users' personal data: emails, phone numbers, SSNs, medical record numbers and other PII in a message.

You usually want the model to reason about this data ("call the payments API", "email this customer") without seeing the actual values. A live API key or a patient's SSN in a model prompt, a tool result, a log line or an external search query is hard to undo.

The SDK applies these controls by default to reduce that exposure:

  1. The model plans against a schema. It sees field names, types and labels, never raw values.
  2. Real values are injected only at tool-execution time, just before your code runs.
  3. Tool results are scanned and redacted to reduce the chance of private values reaching the model.
  4. User message text can be scrubbed for PII before it reaches the model, via RedactedMessage.

The rest of this guide shows the SDK surface behind each one.

#Declaring private data

Private data lives on an Agent in its private_data field. The simplest form is a plain dictionary of key/value pairs.

Python
from maivn import Agent

agent = Agent(name='api_agent', api_key='...')

agent.private_data = {
    'api_key': 'sk-xxx-secret',
    'db_password': 'super-secret-password',
    'user_ssn': '123-45-6789',
}

You can also set it at construction time:

Python
agent = Agent(
    name='api_agent',
    api_key='...',
    private_data={'api_key': 'sk-xxx-secret'},
)
Swarms. Swarm has no private_data field, and a swarm run does not send its member agents' private_data. For values that arrive in a swarm run's messages, use RedactedMessage.known_pii_values. Put work that depends on @depends_on_private_data in a standalone Agent.

#The PrivateData model

The PrivateData model carries a value and optional metadata. Use it in RedactedMessage.known_pii_values when the runtime needs the name, label, entity type or format hint. Passing descriptors to an agent's private_data list keeps only their names and values; that path drops the other metadata.

Python
from maivn import PrivateData

PrivateData(
    value='Maria Santos',       # The actual value (required, never shown to the model)
    name='patient_name',        # Custom key name (instead of an auto-generated one)
    pii_type='person',          # Entity type for categorization
    label='Patient Name',       # Human-readable label in the schema
    description='Full name of the patient from the intake form',
    format='name',              # Semantic format hint
)

Pass a list of PrivateData objects to private_data on an Agent:

Python
agent = Agent(
    name='intake',
    api_key='...',
    private_data=[
        PrivateData(value='claims@hospital.com', name='claims_hotline',
                    label='Claims Hotline', format='email'),
        PrivateData(value='reviews@hospital.com', name='medical_review_email',
                    label='Medical Review Contact', format='email'),
    ],
)
Note Agent lists normalize to a caller map keyed by each descriptor's name. Use that caller key in depends_on_private_data. In a redacted message, declared names are allocated user_ keys, such as user_patient_name. Keep these two input paths distinct when wiring tool dependencies.

For entries in RedactedMessage.known_pii_values:

FeatureRaw stringPrivateData
Key nameAuto-generatedCustom (user_<name>)
Entity typeInferredExplicitly declared
Schema labelNoneCustom
Schema descriptionNoneCustom
Format hintInferredExplicitly declared

#Injecting values into tools

A tool receives a real private value through the @depends_on_private_data decorator. You map a data_key (the name in private_data) to an arg_name (the parameter on your function).

Python
from maivn import depends_on_private_data

@agent.toolify(description='Call external API')
@depends_on_private_data(data_key='api_key', arg_name='key')
def call_api(endpoint: str, key: str) -> dict:
    # 'key' holds the real 'sk-xxx-secret' value at runtime
    return {'status': 'success'}

Stack the decorator to inject several values into the same tool:

Python
@agent.toolify(description='Connect to database')
@depends_on_private_data(data_key='db_host', arg_name='host')
@depends_on_private_data(data_key='db_password', arg_name='password')
def connect_db(query: str, host: str, password: str) -> dict:
    return {'connected': True, 'result': [...]}

The model decides when to call the tool, but it never supplies these arguments. They are filled in for you. See the Dependencies guide for combining private-data injection with other dependency types.

#What the model sees and what runs

This is the core of the security model: the planning stage and the execution stage see different things.

At planning time, the model receives a schema describing the available private data (field names, types and labels, no values):

Plain text
Available private data fields:
- api_key (string): API key for external service
- db_password (string): Database password

It plans which tools to call and in what order, reasoning purely against that schema. The actual values are never part of the prompt.

At execution time, inside the runtime, the real values are looked up and injected into the matching tool arguments just before your function runs. Your tool executes with the real secret; the model is none the wiser.

You can also reference a private value inside a system prompt by its key. The runtime resolves the reference at execution time, so the prompt the model sees carries the placeholder rather than the real value:

Python
agent = Agent(
    name='notifier',
    system_prompt=(
        'You are a notification assistant. '
        "The user's phone is available as the 'phone_number' private value. "
        'Never reveal the actual phone number in your responses.'
    ),
    api_key='...',
)

agent.private_data = {'phone_number': '+1-555-123-4567'}

For most cases, prefer injecting the value straight into a tool argument with @depends_on_private_data(arg_name=...) (shown above). It needs no special prompt syntax and keeps the value out of the prompt entirely.

#Automatic redaction in tool results

A tool might accidentally echo a private value back in its output, for example by interpolating a secret into a message string. The runtime scans tool results for registered private values and replaces matches before forwarding the result to the model. Detection has limits. Transformed values, logs and external side effects need their own controls.

Python
@agent.toolify()
@depends_on_private_data(data_key='secret', arg_name='secret')
def leaky_tool(secret: str) -> dict:
    # Bad practice: putting the secret in the output.
    return {'message': f'Used secret: {secret}'}

# The runtime redacts the 'secret' value from the result
# before the model ever sees it.

This is a safety net, not a license to be careless. Treat private values as write-only inside a tool: use them, never return or log them. See Best Practices below.

#Keep private values masked in output

By default, private values are restored in the final message and result before they reach you, so your application sees the real values. Some callers don't want that: they need to check where a value came from, or they keep private values in their own store, and would rather receive masked output.

Pass restore_private_values=False when constructing the client, and give that client to your agent:

Python
from maivn import Agent, Client

client = Client(api_key='...', restore_private_values=False)
agent = Agent(name='api_agent', client=client)

What this changes: the final output (the final message, the structured result and any buffered final text) keeps placeholders instead of the real values. The client also stops restoring values in the events it streams to you.

What it doesn't change: your local tools still receive real values. Tool-call arguments, including those injected through @depends_on_private_data, are still resolved before your function runs, so private values still travel to your process when a tool needs them. The setting masks what you get back, not what your tools receive.

#Automatic PII detection with RedactedMessage

Secrets are values you know about. PII is often values you don't — whatever a user happens to type into a message. RedactedMessage handles that case: it asks the runtime to detect PII in the message text and substitute placeholders before the content reaches the model.

Python
from maivn import Agent
from maivn.messages import RedactedMessage

agent = Agent(name='support', api_key='...')

response = agent.invoke([
    RedactedMessage(content='My email is john@example.com and SSN is 123-45-6789')
])

What happens:

  1. You send a RedactedMessage.
  2. The runtime detects PII in the content.
  3. Detected values are replaced with stable, opaque placeholders before the text is sent onward.
  4. The original values are registered into the session's private_data — held within the runtime, not surfaced to the model.
  5. The model sees only the placeholders.

Because the detected values land in private_data, you can inject them into tools the same way as any other private value. To depend on a specific value, give it a predictable key by declaring it in known_pii_values with a name (see the next section) and reference that key:

Python
@agent.toolify(description='Send email to user')
@depends_on_private_data(data_key='user_email', arg_name='email')
def send_email(message: str, email: str) -> dict:
    # 'email' holds the original 'john@example.com' at runtime.
    return {'sent': True, 'to': email}

#Declaring known PII alongside the message

You can mix PrivateData descriptors and raw strings in known_pii_values to declare values you already know are in the message, with custom keys and labels:

Python
from maivn.messages import RedactedMessage, PrivateData

response = agent.invoke([
    RedactedMessage(
        content='Process claim CLM-2026-4401 for Maria Santos, DOB 1985-07-14.',
        known_pii_values=[
            PrivateData(value='Maria Santos', name='patient_name', pii_type='person',
                        label='Patient Name'),
            PrivateData(value='1985-07-14', name='patient_dob', pii_type='date',
                        label='Date of Birth', format='date'),
            PrivateData(value='MEM-882441', name='member_id', label='Member ID'),
            '212-555-0101',  # Raw strings still work.
        ],
    )
])

The model then sees opaque placeholders in place of those values. Each detected value is swapped for a stable token keyed to its name (for example, the span for patient_name becomes a placeholder bound to user_patient_name), and the schema gains metadata (names, labels, types) with no values attached.

#Allow-listing safe values

Not every detected span is actually private. A public marketing URL, your organization's own published support email, or an identifier a downstream tool legitimately needs in cleartext should pass through untouched. PIIWhitelist lets you approve those spans without weakening protection for everything else.

The whitelist is evaluated after detection (so the fact that PII was present is still recorded) but before the value is registered into private_data (so no placeholder is substituted for the approved span).

Python
from maivn import PIIWhitelist, PIIWhitelistEntry, RedactedMessage

whitelist = PIIWhitelist(
    entries=(
        # Allow every URL in a non-PHI context.
        PIIWhitelistEntry(
            entity_type='url',
            justification='Public marketing URLs are needed for citations.',
        ),
        # Allow one specific known-safe email.
        PIIWhitelistEntry(
            value='hello@maivn.io',
            justification='Public support address listed on the docs site.',
        ),
        # Allow a bounded family of values via an anchored pattern (use sparingly).
        PIIWhitelistEntry(
            pattern=r'^https://docs\.maivn\.io/.*',
            justification='Public docs URLs only.',
        ),
    ),
    phi_mode=False,  # set True for any deployment handling PHI
)

response = agent.invoke([
    RedactedMessage(
        content='See https://docs.maivn.io/x and email hello@maivn.io',
        pii_whitelist=whitelist,
    ),
])

#Entry shapes

Each PIIWhitelistEntry sets exactly one matcher, plus a required justification:

FieldMatch behaviorUse when
entity_typeSuppresses every detected span of this categoryYou trust an entire category in a non-PHI context
valueCase-insensitive exact match against the detected spanOne known-safe specific value
patternAnchored regex match against the detected spanA bounded family of values (for example one domain)

The justification field is required (8 to 512 characters) and records why the suppression was configured; it is not compliance evidence by itself. A value must be at least 3 characters after trimming, an entity_type is lowercased, and an optional label (up to 128 characters) names the entry.

#PHI mode

When phi_mode=True, the whitelist refuses to construct any entity_type entry that names a HIPAA Safe Harbor identifier category. This is enforced at construction time, so the application rejects that broad whitelist rule before sending a request:

Python
from maivn import PIIWhitelist, PIIWhitelistEntry

# Raises ValueError — `ssn` is a Safe Harbor identifier.
PIIWhitelist(
    entries=(PIIWhitelistEntry(entity_type='ssn', justification='Broad category is not allowed.'),),
    phi_mode=True,
)

# Allowed — value/pattern entries target a single approved instance,
# not a whole category, so they remain valid in PHI mode.
PIIWhitelist(
    entries=(
        PIIWhitelistEntry(
            value='hospital-public@example.org',
            justification='Hospital published support address; legal-approved.',
        ),
    ),
    phi_mode=True,
)

PIIWhitelist and PIIWhitelistEntry are frozen models, immutable after construction. To change a policy, build a new one.

#Where to set the whitelist

A whitelist travels on the pii_whitelist field of an individual RedactedMessage, so you scope it to exactly the messages where the approved spans appear. Reuse the same PIIWhitelist object across messages to apply a consistent policy.

Python
# Attach the whitelist to each RedactedMessage that needs it:
RedactedMessage(content='...', pii_whitelist=whitelist)

The same policy can travel with a file you upload into private custody. See Uploads below.

#Photographs and scanned PDFs

A RedactedMessage can carry a photograph or a PDF as an inline attachment. Before the model, memory, or any stored record sees it, the runtime reads every word on the page, covers what it detects, and sends the covered picture in place of the original. The message's pii_whitelist applies to the page exactly as it applies to the message text, so a timesheet can keep its dates and hours readable while the worker's name is covered:

Python
from pathlib import Path

from maivn import PIIWhitelist, PIIWhitelistEntry
from maivn.messages import RedactedMessage

timesheet_policy = PIIWhitelist(
    entries=(
        PIIWhitelistEntry(
            entity_type='datetime',
            justification='Shift dates and times are the content of a timesheet.',
        ),
        PIIWhitelistEntry(
            entity_type='date',
            justification='Shift dates are the content of a timesheet.',
        ),
    ),
)

response = agent.invoke([
    RedactedMessage(
        content='Total the hours on this timesheet.',
        attachments=[{
            'filename': 'timesheet.png',
            'mime_type': 'image/png',
            'content_bytes': Path('timesheet.png').read_bytes(),
        }],
        pii_whitelist=timesheet_policy,
    ),
])

Things to know:

  • Faces and licence plates are always covered. No whitelist entry can leave them visible.
  • Dates and times on a page are detected as datetime. Approve datetime to keep them readable in pictures; approving both date and datetime covers typed text and pictures alike.
  • known_pii_values are covered on pictures too. Each declared value is covered wherever it appears as whole words on a line the runtime can read, and no whitelist entry uncovers it. A value split across two lines, or in writing too faint to read, is not matched, though detection may still find it.
  • Pages that cannot be read with confidence are refused, not forwarded. Faint handwriting or a blurry photograph can fail the request with a message naming the attachment and the reason. Retake the photograph or send the page as text.
  • The covered picture replaces the original. It gets a neutral filename, because a filename such as Maria Santos timesheet.png is itself the kind of value being protected.
  • It takes longer. Reading a page adds a few seconds before the first event of the run.
  • There are limits per request. One request can carry at most 8 photographs or PDFs, totalling at most 25 MB, and reading them all must finish within 5 minutes. Anything over these limits is refused before it is read. Send more pictures across several requests.
  • phi_mode=True refuses a datetime or date category entry, because dates are a Safe Harbor identifier. Use value or pattern entries for specific approved dates instead.

Video and audio attachments under a RedactedMessage are still refused, because the runtime cannot cover them.

#Uploads

A file you upload with client.resources.upload into a project that keeps private data in its own custody is redacted when it is stored. Pass the same kind of policy with ResourceUploadOptions(pii_whitelist=...) and it covers text documents as well as photographs and scanned PDFs:

Python
from pathlib import Path

from maivn import Client, ResourceScopeRequest, ResourceUploadOptions

client = Client()
resource = client.resources.upload(
    Path('invoice.pdf').read_bytes(),
    media_type='application/pdf',
    name='Invoice',
    options=ResourceUploadOptions(
        scope=ResourceScopeRequest(shared=True),  # one copy for the whole project
        pii_whitelist=timesheet_policy,
    ),
)

An invalid policy, such as a category entry refused by phi_mode, fails the upload instead of being ignored. Projects without private custody store uploads as they are and ignore the field.

#Supported PII types and Safe Harbor categories

Detection targets HIPAA Safe Harbor identifiers plus common PCI, banking, and governmental categories. Each pattern is paired with a structural validator so structurally similar non-PII (order numbers, internal product codes) is far less likely to be flagged.

TypeExamplesValidation approach
emailuser@example.comstructural
phone+1-555-123-4567, (555) 123-4567NANP / E.164 boundaries
ssn123-45-6789rejects reserved area codes
credit_card4111-1111-1111-1111Luhn (mod-10) checksum
ibanDE89370400440532013000per-country length + ISO 13616 mod-97
swiftDEUTDEFF, DEUTDEFF500ISO 3166 country code + length 8 or 11
medical_record_numberMRN: AB-12345label-anchored
vehicle_id1HGCM82633A004352 (VIN)ISO 3779 alphabet + 17 chars
health_plan_idMember ID: HP-994221label-anchored
personNamesconfidence-scored detection
locationAddresses, citiesconfidence-scored detection
date / datetime2025-04-29, April 29, 2025confidence-scored detection
ip_address192.168.1.1confidence-scored detection
urlhttps://...confidence-scored detection

The full set of HIPAA Safe Harbor categories is exported as a public constant so you can validate your own policy before constructing a whitelist:

Python
from maivn import HIPAA_SAFE_HARBOR_CATEGORIES

print(sorted(HIPAA_SAFE_HARBOR_CATEGORIES))
# ['account_id', 'biometric_id', 'certificate_id', 'credit_card', 'date',
#  'datetime', 'device_id', 'email', 'fax', 'health_plan_id', 'iban',
#  'ip_address', 'license_id', 'medical_record_number', 'person', 'phone',
#  'ssn', 'swift', 'url', 'vehicle_id']

#Values that outlive one call

mAIvn keeps none of a conversation's private values once a run ends. Between turns, a conversation on a thread_id has one placeholder map, and it lives in your PrivateDataStore: in your process or on your disk, under your key.

It holds two kinds of value:

  • the values you declared, so you don't re-supply serial_number on every turn;
  • the values the shield discovered during a run, under keys it allocated such as pii_email_1. The run's final event hands them to your client, which keeps them in the store and removes them from the event before your code sees it.

Both are sent back with your next call on the thread, which is how turn two can resolve a value the shield discovered on turn one. If you pass private_data_store=None, nothing is kept, and a later turn shows a placeholder where an earlier turn's discovered value would have been.

When your call and the store hold the same key, what you pass on this call wins.

#Automatic local storage

The SDK installs private-data-vault and uses encrypted local storage by default. On a supported desktop, the OS credential store must be available (signed in and open) when private values are used. The vault opens when needed; installing the SDK does not create one. Persistence needs an explicit thread_id; a call without one passes the map through for that call only.

The store retains string-to-string pairs from the caller's private_data map and the discovered values a run hands back. Other mapping values remain specific to the invocation. Saved pairs are merged into later calls on the same thread, even when the call supplies no private map. New caller values replace the saved values for matching caller keys.

After a restart, reuse the thread ID and keep the same authenticated identity (user, organization and project) and base address. Rotating the API key within that identity does not select a new vault. Keep the vault files and their matching key.

Python
import os
from maivn import Client, RunOptions

client = Client(api_key=os.environ['MAIVN_API_KEY'])
options = RunOptions(thread_id='serial-support')
client.invoke('Use my serial number to check the warranty.', options=options,
              private_data={'serial_number': 'SN-8831'})
client.invoke('Check the same serial again.', options=options)

# Delete saved caller values for this thread on this machine.
client.forget_private_data('serial-support')

Async applications use await client.aforget_private_data(thread_id). Local deletion does not remove server-held data, message history, or uploaded documents. It does not create a vault when there is nothing to delete.

#Servers and containers

Configure both settings in your hosting provider:

  • MAIVN_VAULT_DIRECTORY: an absolute parent directory on durable storage.
  • MAIVN_VAULT_KEY: a base64-encoded, randomly generated 32-byte key injected by your secret manager.

Create the key once and retain it across deployments. Do not use your mAIvn API key or generate a replacement at each startup. Ordinary Client() construction uses these settings. The SDK does not provision storage or a secret manager.

If your application retrieves secrets itself, supply a callable:

Python
from maivn import Client, LocalVaultConfig

# load_vault_key is your secret-manager callback; it returns exactly 32 bytes.
client = Client(local_vault=LocalVaultConfig(
    directory='/srv/my-app/private-values',
    key_provider=load_vault_key,
))

The SDK calls the provider when it opens the vault. Explicit local_vault configuration replaces the environment-based vault settings.

Use a persistent filesystem with working file locks and atomic replacement. Serverless temporary storage cannot retain values between instances. An object-store URL is not a vault directory. Qualify a shared filesystem before using multiple writers.

#Recovery and opt-out

Back up encrypted files and retain their matching key. A new key cannot recover existing records. Desktop credential entries depend on the vault's location; copying files to another path or machine alone does not restore access. Server recovery requires both durable files and the secret-manager key.

If secure storage cannot open, the SDK raises VaultSetupError when private storage is needed. It does not fall back to plaintext or temporary storage. Check the OS credential store, server configuration, and authenticated API connection.

Use Client(private_data_store=None) to disable local persistence explicitly. You can instead pass your own store (see Choosing a store). A custom store and local_vault configuration cannot be combined.

Automatic local storage holds caller-declared placeholder values. Private file uploads and document retrieval keep their own API, authorization and retention requirements. See Artifacts.

#Choosing a store

Client(private_data_store=...) accepts any object that implements the PrivateDataStore protocol. The default (omitting the argument) is the automatic vault described above. The SDK exports three names for this:

NameWhat it is
PrivateDataStoreRuntime-checkable protocol with three async methods: remember(thread_id, mapping) merges pairs into a thread's map, resolve(thread_id, placeholders) returns stored values (an empty sequence asks for the whole map), and forget(thread_id) deletes the map and is idempotent.
InMemoryPrivateDataStoreProcess-lifetime store. Nothing is written to disk, and values are gone when the process exits. Use it for scripts and tests.
EncryptedFilePrivateDataStore(path, secret)Durable store on your disk. Each thread is one sealed record, encrypted with the vault core that the automatic vault uses. You choose the directory and supply the secret as bytes; the key never leaves your machine.
Python
import os
from maivn import Client, EncryptedFilePrivateDataStore, InMemoryPrivateDataStore

# Durable: you own the directory and the secret. Load the secret from your
# secret manager; losing it makes the stored values unrecoverable.
store = EncryptedFilePrivateDataStore('/srv/my-app/private-values', secret=load_secret())
client = Client(private_data_store=store)

# Ephemeral: values last as long as this object.
test_client = Client(private_data_store=InMemoryPrivateDataStore())

load_secret stands for your own secret-manager call and returns bytes. EncryptedFilePrivateDataStore needs the private-data-vault wheel, which is a dependency of the SDK. A wrong secret fails with an authentication error when the store is read.

Every store follows the same rules as the automatic vault: it keeps only string-to-string pairs from the private_data you pass, merges them into later calls on the same thread_id, and never receives values the server allocated during a run. client.forget_private_data(thread_id) calls the store's forget.

#Redaction preview models

RedactionPreviewRequest and RedactionPreviewResponse are exported data models. preview_redaction() builds the request for you, so you rarely construct RedactionPreviewRequest yourself. See Preview redaction for the call and the response fields.

#System tools respect the same boundary

The built-in system tools (web_search, repl, think) honor the same private-data rules as your own tools:

  • web_search applies controls intended to keep registered private values out of outbound queries and scans returned content.
  • repl can run with injected private values and applies redaction controls to output before it returns to the model.
  • think is designed to receive the private-data schema rather than raw values and applies redaction controls to its output.

These are technical controls, not a guarantee that every private value will be detected or contained. See the System Tools guide for the current surface and apply your own testing and governance.

Python
from maivn.messages import HumanMessage

agent.private_data = {'user_email': 'john@example.com'}

# The agent can search for context without leaking the email
# into the external search query.
response = agent.invoke([
    HumanMessage(content="Search for information about this user's preferences")
])

#Best practices

Treat private values as write-only inside a tool. Use them to do work; never return them in a result or write them to a log.

The same rule applies to observability storage. The public maivn.telemetry contract is metadata-only and has no content-export option: message bodies, tool arguments/results, final results, resolved private values, and placeholders are absent from listener events and OpenTelemetry spans.

Python
# Avoid:
def my_tool(secret: str) -> dict:
    print(f'Using secret: {secret}')   # leaks to logs
    return {'secret_used': secret}     # leaks back toward the model

# Prefer:
def my_tool(secret: str) -> dict:
    result = call_api(secret)
    return {'status': 'success'}

Use descriptive key names (stripe_api_key, not key1) so the schema the model plans against is self-explanatory.

Include only what's needed. Every value in private_data enlarges the schema the model sees. Don't register secrets a session won't use.

Turn on PHI mode for any healthcare deployment. phi_mode=True prevents whole-category whitelist entries for Safe Harbor identifiers, so an over-broad policy fails at construction instead of in production.

#How private data compares to environment variables

AspectPrivate dataEnvironment variables
ScopePer-agent / per-swarmProcess-wide
Model visibilitySchema onlyNot visible
Runtime injectionYesNo (static)
Automatic redactionYesNo

Use private data when the model needs to know a value exists, tools need it injected, or you want automatic redaction. Use environment variables for static configuration consumed at SDK initialization where no model awareness is needed.

#Next steps

#Reviewing over-redaction guidance

Since SDK 2.2.0, InvokeResponse.privacy_guidance is a list of advisory objects, empty by default. It helps you review likely over-redaction without changing shielded context or creating a whitelist for you.

The delivered advisory may contain the actual value that was redacted. Show it only in a trusted developer interface. Never log or persist it, send it to a model, or forward it wholesale to end users. repr=False hides it from the response representation; it does not remove it from model_dump() or JSON. Select safe fields when you serialize a response.

Review any proposed PIIWhitelistEntry and its justification before applying it to a later RedactedMessage. Absence of guidance is not proof that every detection was correct. Decision results have no privacy_guidance field.

Guidance delivered in the raw terminal final event can populate InvokeResponse. Generic normalized final-event builders do not promise to forward it. Keep a separate trusted developer channel instead of bypassing frontend_safe protections.

#Preview redaction

Since SDK 2.4.0, Client.preview_redaction() shows what a run would send to the model provider before you run it, including covered picture regions. Preview a prompt and a PDF:

Python
from pathlib import Path
from maivn import Client, RunOptions

client = Client()
preview = client.preview_redaction(
    'Review this document for Alice.',
    attachments=[{'filename': 'document.pdf', 'mime_type': 'application/pdf',
                  'content_bytes': Path('document.pdf').read_bytes()}],
)
for item in preview.items:
    print(item.key, item.pii_type, item.regions)
for index, entry in enumerate(preview.inputs):
    if entry.covered_image is not None:
        print(index, entry.covered_image.media_type, len(preview.covered_bytes(index)))
local_values = preview.local_values()  # extracted locally from your original text
# After you review the covered pages, the text and the item list:
result = client.invoke(
    preview.approved_messages(),
    options=RunOptions(redaction_preview_id=preview.preview_id),
)

apreview_redaction is the async equivalent.

When the run goes through an agent or swarm that has a system_prompt, preview with agent.preview_redaction(...) or swarm.preview_redaction(...) (async apreview_redaction) instead. They take the same keyword options and prepend the system prompt exactly as invoke does, so the approved copy matches the run:

Python
preview = agent.preview_redaction('Review this document for Alice.')
result = agent.invoke(
    preview.approved_messages(),
    options=RunOptions(redaction_preview_id=preview.preview_id),
)

A client-level preview run through an agent with a system prompt fails with redaction_preview_mismatch, because the agent adds a message the preview did not include. These scope methods need maivn 3.1.0 or later.

A bare HTTP 503 from preview_redaction, review_redaction or approve_redaction is deployment configuration, not a problem with your request: the project's private-data vault is off, its tenant encryption keys are missing, or key custody is set to ordinary. Ask the platform operator to enable the vault with tenant keys and non-ordinary custody.

#Request

preview_redaction(prompt, *, attachments=None, resources=None, pii_whitelist=None, known_pii_values=None, cover_regions=None, timeout_seconds=300.0). The prompt can be a string, a RedactedMessage or a list of RedactedMessage. The call waits up to 300 seconds by default; pass timeout_seconds to change that. Previews are rate limited per project, and a limited request fails with HTTP 429 and a Retry-After header.

#Response

  • inputs: one entry per prompt, attachment or stored resource, with status (redacted, unchanged or refused), refusal (code and reason), and the rendering: redacted_text or covered_image. Check each input's status and refusal before you use its rendering.
  • items: one entry per redaction, with key, placeholder, pii_type, source (detected, declared, known_pii, caller_region or pattern), spans, regions (picture placements) and confidence. Items never contain the value.
  • stats, declared_matched and declared_unmatched: counts, and which of your declared values did or did not match.
  • preview_id and approved_request: the single-use ticket and the exact shielded messages it seals. The server may return no preview ID, including for refused inputs or resource references.

local_values() runs locally on your original text and is excluded from model serialization. Resources and picture regions have no locally extracted text. covered_bytes(input_index) returns the covered image or PDF for an input, or None.

#Run on the approved copy

When an ID is issued, approved_request holds the shielded messages, structured text and image blocks, staff legend, covered attachments and policy sealed by that ticket. approved_messages() returns independent SDK messages marked already approved; invoke sends them unchanged without redacting them again. Pass those messages and the matching redaction_preview_id to invoke or ainvoke.

Two local checks guard this path. approved_messages() raises ValueError("redaction_preview_unavailable") for a preview with no ticket or approved copy. invoke and ainvoke raise ValueError("redaction_preview_mismatch") before sending anything if you change a message, the policy or an attachment, add private data, or pass a different ticket. Tickets are single-use and expire (24 hours by default); an expired ticket needs another preview and review.

#Staff-drawn covers

To add an unconditional cover, pass cover_regions=[CoverRegion(...)] to preview_redaction or to a RedactedMessage. CoverRegion takes an attachment ID, a one-based page and a bbox=(x, y, width, height) in page fractions; box and key are accepted input aliases for bbox and name. Labels and descriptions are optional. A PrivateData label travels with a known value, and a literal whitelist entry needs a justification. approved_messages() keeps these covers and the policy for the run; a whitelist cannot uncover a caller region.