Mask File
Mask personal and financial data in extracted file text, with support for streamed uploads, adjustable detection, and excluded entity reporting.
File masking
PUT /mask/file/async masks the text of a file in the background. Send one base64-encoded file per request. The API returns a tracking ID once the whole file has been validated and stored, then extracts its text, detects sensitive data, and masks it.
The result is the masked text of the file, not a rebuilt file.
Supported file types
| Group | Types |
|---|---|
| PDF (text-based, scanned, and mixed pages) | |
| Word and text | DOCX, DOC, TXT |
| Images | PNG, JPG, JPEG, BMP, TIF, TIFF |
Endpoint
Send a request to either route to mask a file:
| Method | Route | Headers |
|---|---|---|
| PUT | {baseurl}/vault/mask/file/async?stream=false | Authorization: Bearer <vault-user-api-key>, Content-Type: application/json |
| PUT | {baseurl}/vault/mask/file/async?stream=true | Authorization: Bearer <vault-user-api-key>, Content-Type: application/json |
The API key needs the mask permission.
Query parameters
The optional stream parameter defaults to false. Only this parameter differs between the two modes; the body, response, and errors are the same.
stream | Use for | Default limit |
|---|---|---|
false | Files up to the limit; the body is read whole, then validated. | 2 MiB of base64 |
true | Larger files, or when the size is unknown; the file is processed in chunks as it arrives. | 10 MiB of base64 |
The limits are defaults and may change.
Request body
Each request contains exactly one file item.
| Field | Type | Required | Description |
|---|---|---|---|
mask | array | Yes | Exactly one file item. |
mask[].file_content | string | Yes | The file, base64-encoded. |
mask[].file_type | string | Yes | The file extension without the dot, in any case, such as PDF or docx. Must be a supported type. |
mask[].file_bytes | integer | Yes | The length of the file_content string in characters, not the size of the original file. Every character counts, including = padding and any line breaks. |
mask[].file_name | string | No | The file's name, returned with the result. |
policy_name | string | No | The policy to apply. If omitted, your namespace's default policy is used. An unknown name is rejected. |
effort | string | No | medium (default) or high. |
identify_excluded_entities | boolean | No | true (default) or false. When true, entities your policy excludes are reported in excluded_entities. |
Work out file_bytes
The text Hello encodes to the base64 string SGVsbG8=, which is 8 characters, so the item sends "file_bytes": 8. In code, use the length of the base64 string, such as len(file_content) in Python.
Example request
{
"mask": [
{
"file_content": "JVBERi0xLjMKJZOMi54gUmVwb3J0TGFi...",
"file_type": "PDF",
"file_name": "abc.pdf",
"file_bytes": 1928
}
],
"policy_name": "customer_mask_policy",
"effort": "high"
}
Response
When the file has been validated and stored, the call returns HTTP 200 with a tracking ID and the status PENDING.
| Field | Description |
|---|---|
data | The tracking ID and status. |
data[].tracking_id | The file job's tracking ID. |
data[].status | The job status, initially PENDING. |
success | Whether the request succeeded. |
error.message | The error message. |
Example response
{
"data": [{"tracking_id": "dbb13c32-7d26-4dc3-a182-e8582739188803122026051650", "status": "PENDING"}],
"success": true,
"error": {"message": ""}
}
Poll PUT /mask/file/async-status with the tracking_id until the status is SUCCESS or FAILED, then fetch the result with include_result=true.
Masking behavior
The API extracts text from the file first. Scanned PDFs and images are read with text recognition. The active policy controls which entities are detected, how they are tokenized, and which tags wrap them.
Entities excluded by the policy are never masked. With identify_excluded_entities set to true, they are reported in excluded_entities.
Errors
Invalid requests are rejected immediately with HTTP 500, success: false, and the reason in error.message. No tracking ID is created. With stream=true, file checks happen once the whole body has been read.
A request is rejected when:
- The request contains text items (
value), or an item has bothvalueandfile_content. - There is more than one file item.
file_content,file_type, orfile_bytesis missing, orfile_contentis not valid base64.file_typeis not a supported type.file_bytesis not a positive whole number, or does not match the length offile_content(the file did not arrive complete).- The file is over the
stream=falselimit. Send it again withstream=true. effortis notmediumorhigh, oridentify_excluded_entitiesis nottrueorfalse.policy_namedoes not exist in your namespace.
If the file cannot be read or masked after it has been accepted, the job ends as FAILED with the reason in error_msg, for example when a file is damaged.