Masking a card number on a report is easy. Keeping the card number useful while nobody can read it is harder. The settlement job still has to join card records across tables, the support desk still needs the last four digits to match a caller, and the fraud team occasionally needs the full number for a chargeback form. Tokens solve this: a value with the same shape as the original that carries none of its meaning. InsightAIShield makes tokens three ways — computed with format-preserving encryption, drawn at random and sealed in a vault, or hashed one way — and this post is about choosing between them, column by column, on the fictional Northmere Bank’s demo estate.

In short

  • Three modes, one format catalogue. fpe computes the token with NIST FF1 or FF3-1, vault draws a random token and seals the value with AES-GCM, one-way renders a keyed HMAC-SHA256 in the value’s shape and can never be reversed.
  • The shape stays. Seven built-in formats keep length, separators and, where you choose, the first or last four characters in clear, so validations, joins and look-ups keep working.
  • Keys are references. A key row names where the key lives (env://, aws-kms://, aws-sm://, a file); the material is never stored or shown, and rotation keeps old tokens readable.
  • Detokenizing is a person’s act. It needs a purpose in words and permission for the column, is capped at 1,000 tokens per 60 minutes per person by default, and every attempt is recorded, allowed or not.

What a token has to do

A token stands in for a sensitive value wherever the value itself isn’t needed. That sounds like a single requirement, but in practice a column asks four questions of its token:

  • Does it fit? A card number column with a Luhn check, a fixed width and dashes in set places will reject a token that looks like a UUID. Applications break on shape before they break on meaning.
  • Does it join? If the same card number appears in the card table and in the dispute table, both must get the same token, or every report that links them falls apart.
  • Can it come back? Some columns need the clear value again for a narrow purpose (a chargeback, a regulator’s request). Others never should.
  • Where does the secret live? Either the value is recoverable from the token with a key, or it is stored somewhere and the token is a pointer to it. Each choice puts the risk in a different place.

The three modes in InsightAIShield answer these differently, and all three use the same catalogue of formats, so the decision about shape is separate from the decision about recoverability.

Formats: the shape, chosen once

A format says which characters are replaced and which stay. There are seven built in. The numeric ones replace digits with digits and leave separators and punctuation where they were; the letters-and-digits ones do the same for alphanumeric values such as account identifiers or IBAN-like strings. Each comes in three variants: everything replaced, the last four left in clear (card and account look-ups), or the first four left in clear (issuer ranges). The seventh, a random GUID, carries nothing of the value at all and is only used in vault mode. A team that needs something else adds a custom format: its own alphabet, how many characters to keep on the left or right, and an optional prefix.

The Formats tab of InsightAIShield's tokenization page: seven built-in formats, each with a description, an example value such as 4111-1111-1111-1111 and the token it produces, for example 9190-9097-4224-1111 for numeric with the last four in clear.
Demo data The seven built-in formats, each with an example and its token. NUMERIC_SAME_LAST_FOUR turns 4111-1111-1111-1111 into 9190-9097-4224-1111: same dashes, same length, same last four.

The last-four variant is the one most banks reach for first. A support agent confirming “the card ending 1111” sees exactly what they need, and the remaining twelve digits are noise with the right shape. The first-four variant suits analytics on issuer ranges, where the bank identification digits matter and the account digits don’t.

Three ways to make the token

fpe

vault

one-way

Clear value
4111-1111-1111-1111

Mode for
this column

FF1 or FF3-1
key + per-column tweak

Random token
value sealed with AES-GCM

Keyed HMAC-SHA256
in the format's shape

Token computed,
reversible with the key

Token stored,
reversible from the vault

Token computed,
never reversible

One format catalogue, three modes. The format decides the shape; the mode decides how the token is made and whether it can come back.

Format-preserving encryption (fpe)

FF1 and FF3-1 are the two modes of NIST SP 800-38G Rev. 1. They encrypt a string of numerals into another string of the same length over the same alphabet, so a sixteen-digit number becomes a sixteen-digit number. Nothing is stored: the token is computed from the value, the key and a tweak, and the clear value is computed back from the token with the same key and tweak. InsightAIShield derives the tweak per column from the column’s scope (for example cards_mysql.cards.card.pan), so the same card number in two different columns gives two different tokens, while the same number in the same column always gives the same token and still joins.

Two details matter here. First, the implementation checks the standard’s length rules for each alphabet before it encrypts, so a value too short to encrypt safely is refused rather than weakly encrypted. Second, FF3-1 uses the 56-bit tweak of the revised standard; the original FF3, withdrawn after a published attack, exists in the code only so the tests can check it against NIST’s samples, and is never used to tokenize.

Vaultless tokens are the right choice when volume is high and the clear value is needed back by systems, not by people browsing a table: a payment pipeline that tokenizes at ingestion and detokenizes at the point of settlement, for instance. The cost is that whoever holds the key and the scope can reverse every token, so the key is the whole secret.

The vault

In vault mode the token is drawn at random in the chosen format and the clear value is sealed with AES-GCM and kept in the vault. A keyed HMAC of the format, scope and value acts as the lookup, so the same value in the same column always returns the same token: joins work exactly as with FPE. Reversing a token means finding its row and unsealing it, which happens only through the detokenize request described below. The token itself contains no information about the value, so a token leaked without the vault is just a string. This suits values people occasionally need in clear, such as SSNs in a KYC lake or card numbers in a dispute table.

One-way

One-way tokens are a keyed HMAC-SHA256 rendered in the format’s shape. They are deterministic, so they still join and still count distinct values, and nobody can turn them back into the original, with or without the vault. Use them for analytics columns where nobody should ever see the value again: an email address used only to count unique customers in the warehouse is the demo’s example.

fpe (FF1 / FF3-1)vaultone-way
Token keeps the shapeYes, same length and alphabetYes, per the format (or a GUID)Yes, per the format
Same value, same column, same tokenYes (per-column tweak)Yes (keyed HMAC lookup)Yes
StoredNothing but a listing rowThe value, sealed with AES-GCMNothing but a listing row
Back to clearWith the key, through detokenizeFrom the vault, through detokenizeNever
Typical columnHigh-volume pipeline fieldsSSNs, PANs people sometimes needAnalytics identifiers

What the demo vault holds

On Northmere’s estate the vault lists 11 tokens across 4 columns, one of them one-way: card numbers from the cards platform, three SSNs from the KYC table in the lake, and a one-way email from the warehouse’s customer view. The vault page shows each token, its format, its scope, the key and key version that made it, its kind and how often it has been used. The clear values are never on this page.

The Vault tab: 11 tokens in the vault across 4 columns with 1 one-way, 2 active keys, and a table of tokens with their format, scope such as lake.northmere_lake.raw_kyc.ssn, key demo_ff1@v1, kind vault or one-way, uses and age.
Demo data The vault lists tokens, never values. Each row carries its scope and the key version that made it, so a rotation never orphans a token.

Keys that are only references

A key in InsightAIShield is a row that names an algorithm (FF1 or FF3-1), a reference to where the key material lives, a version and a status. The demo has two, demo_ff1 and demo_ff31, both pointing at env://SHIELD_TOKEN_KEY; in production the reference is a KMS or secrets-manager path. From the one master key, separate sub-keys are derived with HKDF-SHA256 for encryption, sealing and hashing, so no single derived key does two jobs.

Rotation retires the current version and activates the next with a new reference. Tokens remember the version that made them (demo_ff1@v1 in the vault listing), so tokens made before a rotation still detokenize, and new tokens use the new key. The audit line says exactly that: which version was retired, which is active.

The Keys tab: two keys, demo_ff1 with algorithm FF1 and demo_ff31 with algorithm FF3-1, each referencing env://SHIELD_TOKEN_KEY, version v1, status Active, with a Rotate button.
Demo data Keys by reference only. The material stays in the secret store; the page shows where it is, the version and how many tokens it made.

Tokens on the way out, not just at rest

Tokenizing a column at rest is a migration. InsightAIShield can also tokenize on the response, which needs no migration at all. A policy rule of type TOKENIZE names a format, a key and a scope; when a query reads that column through the proxy or the query gateway, the value in the result set is replaced with its token before it leaves. The query itself is unchanged. The demo’s customer support assistant, an AI agent, reads account details this way:

The policy simulator's result for the support assistant: the original query selecting account_id, account_number and balance for customer 100042, the rewritten SQL with LIMIT 50, the note that account_number is tokenized on the response, and the reasons Limit, Tokenize and Grant from ai_agent_data v1.
Demo data The agent asks for account numbers and gets tokens: same shape, last four kept. The limit is added to the SQL; the token is applied to the response.

The agent can still read a customer the last four digits of an account and still pass the token to the next tool call, but nothing it holds, logs or sends to a model is a real account number. A HASH rule does the same with a one-way token. When two rules protect one column, the stronger wins: block, then tokenize, then hash, then redact, then mask.

Getting the clear value back

Every token mode except one-way can be reversed, so reversal is where the controls sit. A detokenize request needs three things: the tokens and their scope, a purpose written in words (a short phrase with real words in it; “asdf” is refused), and a requester who is allowed to see that scope in clear, a data security lead by default. An agent is never allowed: the vault refuses an agent as the requester and records the attempt. Each person also has an allowance, 1,000 tokens per 60 minutes by default, set with SHIELD_DETOKENIZE_LIMIT and SHIELD_DETOKENIZE_PERIOD_MINUTES.

A detokenize requestWhat the vault checks, in order; every outcome is recorded
1
Who is asking?

An AI agent is refused outright. A person must be allowed to see this scope in clear.

2
Why?

The purpose must be in words. It is stored with the request and shown on the Detokenize requests tab.

3
How many so far?

Tokens already revealed to this person in the period, against the allowance.

4
Reveal and record

Values returned; the request row and an audit line keep who, why, which scope, how many and the outcome.

In the demo, two requests sit side by side. An analyst asked for one card number “looking at the card for a customer call” and was denied: not allowed to see that scope in clear. The data security administrator asked for two “for chargeback 7781: the card network asks for the full PAN on the dispute form” and was allowed; two values were revealed. Both rows stay.

The Detokenize requests tab: one request from avery.brooks@northmere.example for one token on cards_mysql.cards.card.pan, denied because not allowed to see this scope in clear, and one from sam.rivera@northmere.example for two tokens for chargeback 7781, allowed with 2 revealed.
Demo data Every attempt is on the record, including the refusal. The purpose is in the requester’s own words.

Choosing, column by column

Start from the question each column has to answer. If nobody should ever see the value again, use one-way and stop worrying about it. If people need it back occasionally and you want leaked tokens to be worthless on their own, use the vault. If systems need it back at volume and you are comfortable that the key is the secret, use FF1 (or FF3-1 where an existing standard requires it). In every case pick the format by what the column’s consumers check: the last four for look-ups, the first four for issuer analytics, full replacement otherwise.

Shape is a format decision. Recoverability is a mode decision. Reversal is a person’s decision.

Keeping the three apart is what lets a bank tokenize widely without breaking its applications, and still answer who saw which clear value, when and why.

Where people stay in charge

  • Agents never detokenize: the vault refuses an agent as the requester, and a person states the purpose in words.
  • Every agent action is capped at L2, “ask first”: an agent prepares, and a person confirms, activates, revokes, sends or decides.
  • A policy version goes live only when a second lead, not the person who proposed it, approves it.
  • A revocation is proposed by one reviewer and approved by another; the REVOKE statement is kept on the record for your DBA to run.
  • Detokenizing needs a stated purpose, is recorded, and is capped per person per period.
  • SIEM batches and attestation requests are held until a person releases them.

Keep reading