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

GroupTypes
PDFPDF (text-based, scanned, and mixed pages)
Word and textDOCX, DOC, TXT
ImagesPNG, JPG, JPEG, BMP, TIF, TIFF

Endpoint

Send a request to either route to mask a file:

MethodRouteHeaders
PUT{baseurl}/vault/mask/file/async?stream=falseAuthorization: Bearer <vault-user-api-key>, Content-Type: application/json
PUT{baseurl}/vault/mask/file/async?stream=trueAuthorization: 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.

streamUse forDefault limit
falseFiles up to the limit; the body is read whole, then validated.2 MiB of base64
trueLarger 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.

FieldTypeRequiredDescription
maskarrayYesExactly one file item.
mask[].file_contentstringYesThe file, base64-encoded.
mask[].file_typestringYesThe file extension without the dot, in any case, such as PDF or docx. Must be a supported type.
mask[].file_bytesintegerYesThe 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_namestringNoThe file's name, returned with the result.
policy_namestringNoThe policy to apply. If omitted, your namespace's default policy is used. An unknown name is rejected.
effortstringNomedium (default) or high.
identify_excluded_entitiesbooleanNotrue (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.

FieldDescription
dataThe tracking ID and status.
data[].tracking_idThe file job's tracking ID.
data[].statusThe job status, initially PENDING.
successWhether the request succeeded.
error.messageThe 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 both value and file_content.
  • There is more than one file item.
  • file_content, file_type, or file_bytes is missing, or file_content is not valid base64.
  • file_type is not a supported type.
  • file_bytes is not a positive whole number, or does not match the length of file_content (the file did not arrive complete).
  • The file is over the stream=false limit. Send it again with stream=true.
  • effort is not medium or high, or identify_excluded_entities is not true or false.
  • policy_name does 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.