Use the mask function for data masking
The mask function provides intelligent data masking that goes beyond regular expressions. It supports keyword-based and built-in rule matching to protect sensitive data and meet compliance requirements.
Limits
The mask function is available only for the data transformation (new version) and ingest processor.
Overview of data masking solutions
Background
As data volumes grow, regulations such as GDPR impose strict requirements on how organizations handle sensitive information.
Regular expression masking
SLS provides flexible pipelines that combine data ingestion and masking. Detailed practices for cloud data security protection: Sensitive log scanning and masking.
-
LoongCollector client-side masking:
-
Configure the masking plugin in the collection configuration to replace sensitive fields by regular expression.
-
Use the regexp_replace function in an SPL statement for high-performance server-side masking.
-
-
LoongCollector/SDK + ingest processor:
-
LoongCollector or an SDK handles ingestion. An ingest processor then applies the regexp_replace function for masking, offloading work from the client.
-
Upgraded masking solution: mask function
Regular expression masking can be complex and hard to maintain. The mask function provides a simpler and faster alternative with built-in intelligence.
mask function
Function syntax
mask(field, varchar params)
Parameters
|
Parameter |
Description |
|
field |
The name of the source field to mask. |
|
param |
A JSON array of one or more param rules. |
param rules
|
Parameter |
Required |
Description |
|
mode |
Yes |
The masking mode:
|
|
types |
Required if |
The list of built-in rules for
PHONE, IDCARD, and IMSI can use region-specific rules that you select by using The semantic types for |
|
keys |
Required if |
Defines a list of keywords to match, such as |
|
regions |
No |
The built-in region rules to use. This parameter takes effect only for |
|
maskChar |
No |
The character used for masking. The default is |
|
keepPrefix |
No |
The number of characters to keep at the beginning of the field in character masking. The default is 0. For example, |
|
keepSuffix |
No |
The number of characters to keep at the end of the field in character masking. The default is 0. For example, |
|
maskType |
No |
The masking method:
|
|
maskBeforeChar |
No |
The anchor character to use when |
|
prependPlaceholder |
No |
A Boolean value. The default is |
keepPrefix and keepSuffix apply only to character masking. The anchor method uses the anchor parameter, and the placeholder method uses placeholders.
Built-in types and region coverage
|
types |
Identification target |
regions support |
|
|
Mobile phone numbers |
Supported. See the region matrix below. |
|
|
Identity card numbers or personal identification numbers |
Supported. See the region matrix below. |
|
|
International Mobile Subscriber Identity (IMSI) numbers |
Supported. See the region matrix below. |
|
|
17-character vehicle identification numbers |
Region switching is not supported. Values are identified based on the built-in format and check rules. |
|
|
License plate numbers in the Chinese mainland |
Region switching is not supported. Only rules for the Chinese mainland are available. |
|
|
Landline phone numbers in the Chinese mainland |
Region switching is not supported. Only rules for the Chinese mainland are available. |
|
|
Email addresses |
Rules are not selected by region. |
|
|
Bank card numbers |
Rules are not selected by region. Values must match the built-in format and check rules. |
|
|
IPv4 addresses |
Rules are not selected by region. |
|
|
Alibaba Cloud AccessKey IDs that start with |
Rules are not selected by region. |
|
|
API keys in the supported |
Rules are not selected by region. |
Only PHONE, IDCARD, and IMSI support region switching. In the following table, a hyphen (—) indicates that no built-in rule is currently available.
|
regions code |
Country or region |
PHONE |
IDCARD |
IMSI |
|
|
The Chinese mainland |
Supported |
Supported |
Supported |
|
|
China (Hong Kong) |
Supported |
Supported |
Supported |
|
|
Germany |
Supported |
— |
Supported |
|
|
United Kingdom |
Supported |
— |
Supported |
|
|
United Arab Emirates |
Supported |
— |
Supported |
|
|
Saudi Arabia |
Supported |
— |
Supported |
|
|
Singapore |
Supported |
— |
Supported |
|
|
Kazakhstan |
Supported |
Supported |
— |
|
|
Uzbekistan |
Supported |
Supported |
— |
|
|
Russia |
Supported |
— |
— |
Examples
Example 1: Mask transaction data
A DeFi platform logs on-chain transactions that contain sensitive data such as wallet addresses and transaction hashes. This example masks the wallet, address, sourceIp, phone, and transactionHash fields, keeping the first 3 and last 3 characters for traceability.
-
Raw data
2025-08-20 18:04:40,998 INFO blockchain-event-poller-3 [10.0.1.20] [com.service.listener.TransactionStatusListener:65] [TransactionStatusListener#handleSuccessfulTransaction]{"message":"On-chain transaction successfully confirmed","confirmationDetails":{"transactionHash":"0x2baf892e9a164b1979","status":"success","blockNumber":45101239,"gasUsed":189543,"effectiveGasPrice":"58.2 Gwei","userProfileSnapshot":{"wallet":"0x71C7656EC7a5f6d8A7C4","sourceIp":"203.0.113.55","phone":"19901012345","address":"No. 1000 Wenming Road, Pudong New Area, Shanghai","birthday":null}}} -
SPL statement
SPL statement for the data processor:
*| extend content = mask(content,'[ {"mode":"keyword","keys":["wallet","address","sourceIp","phone","transactionHash"], "maskChar":"*","keepPrefix":3,"keepSuffix":3} ]') -
Output
2025-08-20 18:04: 40, 998 INFO blockchain-event-poller-3 [10.0.1.20][com.service.listener.TransactionStatusListener: 65]][TransactionStatusListener#handleSuccessfulTransaction]{"message": "On-chain transaction successfully confirmed", "confirmationDetails": {"transactionHash": "0×2**************979", "status": "success", "blockNumber": 45101239, "gasUsed": 189543, "effectiveGasPrice": "58.2 Gwei", "userProfileSnapshot": {"wallet": "0x7****************7C4", "sourceIp": "203******.55", "phone": "199*****345", "address": "Shanghai*********No. 00", "birthday": null}}}
Example 2: Mask sensitive URI parameters in NGINX logs
This example masks the uid and token parameters in a request URI, keeping the first 2 and last 2 characters.
-
Raw data
A typical API access log containing user identity and session tokens:
http_protocol: HTTP/1.1 remote_addrs: 127.0.0.1 request_time: 5000 status: 302 time_local: 2025-08-19T18:52:03+08: 00 uri: "uid=user12345&token=bf81639a41d604&from=web" user_agent: Mozilla/5.0(Windows NT 5.2; WOW64))AppleWebKit/535.1( (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1 -
SPL statement
Use
keywordmode to selectively mask URI parameters:* | extend uri=mask(uri, '[ {"mode": "keyword", "keys": ["uid", "loginIp", "token"], "maskChar": "*", "keepPrefix": 2, "keepSuffix": 2} ]') -
Output
http_protocol: HTTP/1.1 remote_addrs: 127.0.0.1 request_time: 5000 status: 302 time_local: 2025-08-19T18:52:03+08: 00 uri: uid=us*****45&token=bf**********04&from=web user_agent: Mozilla/5.0(Windows NT 5.2; WOW64))AppleWebKit/535.1( (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1
Example 3: Mask large model interaction logs
An AI customer service platform receives user messages containing phone numbers, ID numbers, and credit card numbers. This example automatically detects and masks PII in user input while preserving text meaning for downstream analysis.
-
Raw data
A user message containing multiple types of PII:
Hello, I need urgent help! I am a long-term paying user of your platform, my account seems to be locked, and an annual membership renewal has failed. I am in a hurry because I need to use your advanced features to complete a project tonight. Here is all my information. Please have your system administrator or technical support verify and resolve the issue for me immediately: Name: Zhang Wei Registered mobile number: 19901012345 Registered email address: zhangwei.service@example.com Last logon IP address: 203.0.113.55 ID card number: 110105199003070033 The credit card information used for payment is as follows: Credit card type: Visa Card number: 4539-1488-0343-6467 Cardholder name: ZHANG WEI Expiration date: 12/25 CVV code: 123 Please handle this as soon as possible. Thank you very much! I really need your help! -
SPL statement
-
Use
buildinmode to identify multiple types of sensitive information: -
Rules breakdown:
-
Rule 1 fully masks IP addresses, email addresses, and landline phone numbers with
*. -
Rule 2 partially masks phone numbers, ID card numbers, and credit card numbers, keeping the first 3 and last 4 characters.
-
* | extend content = mask(content,'[ {"mode":"buildin","types":["IP_ADDRESS","EMAIL","LANDLINE_PHONE"]}, {"mode":"buildin","types":["PHONE","IDCARD","CREDIT_CARD"], "maskChar":"*","keepPrefix":3,"keepSuffix":4} ]') -
-
Output
content: Hello, I need urgent help! I am a long-term paid user of your platform. My account seems to be locked, and a renewal payment for my annual membership failed. I am very anxious because I need to use your advanced features tonight to complete a project. Here is all my information. Please have your system administrator or technical support verify and resolve the issue for me immediately: Name: Zhang Wei Registered phone number is 199****2345 Registered email is **************************** My last logon IP address was ************ ID card number is 110***********0033 The credit card information used for payment is as follows: Credit card type: Visa Card number is 453************6467 Cardholder name: ZHANG WEI Expiration date: 12/25 CVV code: 123 Please handle this as soon as possible. Thank you very much! I really need your help!
Example 4: Mask vehicle event processing logs
Vehicle signals pass through a message queue into rule computation and cloud diagnostic services, and event logs record the VIN, software version, signal values, and rule results. The same VIN may appear in both the event header and the nested payload, so the rules must cover every match in the body. In the following coolant temperature evaluation log, both VINs are replaced with placeholders, the first two characters of the license plate are kept, and the API token is replaced by business key. The configuration is applied to the entire content field.
-
Raw data
{ "time": "2026-10-13T09:18:42.036+08:00", "level": "INFO", "service": "vehicle-event-processor", "trace_id": "demo-event-a201", "event": "vehicle_signal_evaluated", "vin": "LZZAB12C7T1006842", "plate_no": "粤B24680", "payload": { "vin": "LZZAB12C7T1006842", "signal": "coolant_temperature", "value": 94, "rule_id": "coolant_temp_guard", "rule_version": "r12", "decision": "NORMAL" }, "software_version": "5.4.0", "mq": { "topic": "vehicle.signal.events", "partition": 3, "offset": 873204 }, "latency_ms": 21, "token": "demo_vehicle_token_82" } -
SPL statement
Use the following SPL statement in an ingest processor:
* | extend content = mask(content, '[ {"mode":"buildin","types":["VIN"],"maskType":"placeholder"}, {"mode":"buildin","types":["LICENSE_PLATE"],"keepPrefix":2}, {"mode":"keyword","keys":["token"],"maskType":"placeholder"} ]') -
Output
Both the outer
vinandpayload.vinbecome[VIN_MASKED], the license plate becomes粤B*****, and the token is replaced with the keyword placeholder. The signal value 94, the decisionNORMAL, the rule versionr12, and the software version5.4.0keep their original values, so you can still check the event content and versions.mq.offsetkeeps the consumer offset, andlatency_mskeeps the processing latency.Built-in VIN recognition includes format and check conditions. Vehicle identifiers in an abnormal format can be handled by adding known keys. To trace events across logs, use an evaluated event ID or trace ID. Placeholders and partially masked vehicle identifiers cannot serve as unique correlation keys.
Example 5: Mask owner identity verification and vehicle binding logs
User center logs record requests for owner identity verification and vehicle binding. Identity information may appear in request parameters, and the user ID may appear in both the request and the database query context. When you inspect these APIs, personal information must be hidden while the verification result and binding status are kept. owner_name and user_id are replaced with keyword placeholders, the first 3 and last 4 digits of the Chinese mainland mobile phone number are kept, and the identity card number is fully replaced.
-
Raw data
2026-10-13 09:24:16.218 INFO [owner-identity-service] trace_id=demo-owner-b018 uri=/api/owners/bind method=POST cost_ms=38 status=200 { "request": { "owner_name": "陈宁", "phone": "13900004567", "id_card": "320104199408190028", "user_id": "owner-demo-018" }, "response": { "verification": "PASS", "binding_status": "SUCCESS", "code": "OK" }, "query": { "mapper": "OwnerBindingRepository.findByUser", "user_id": "owner-demo-018" } } -
SPL statement
Use the following SPL statement in an ingest processor:
* | extend content = mask(content, '[ {"mode":"buildin","types":["PHONE"],"keepPrefix":3,"keepSuffix":4}, {"mode":"buildin","types":["IDCARD"],"maskType":"placeholder"}, {"mode":"keyword","keys":["owner_name","user_id"],"maskType":"placeholder"} ]') -
Output
Both
user_idvalues in the request and the query are replaced, the name and the complete identity card number no longer appear in the body, and the first 3 and last 4 digits of the mobile phone number are kept.verification=PASS,binding_status=SUCCESS, andcode=OKare kept, which confirms that the request passed verification and the binding is complete. The API path, trace ID, and the 38 ms latency in the log header also keep their original values. The user ID is recorded as a string, so the JSON body can still be parsed after replacement.A
keywordconfiguration must contain the actual key names. Check each naming variant, such asowner_nameanduserName, separately. If your business does not require manual verification of numbers, you can use placeholders instead. Also check the request, response, and query context for duplicated information.
Example 6: Mask overseas connectivity subscription status query logs
The T-Box or communication module of a vehicle connects to mobile networks through a SIM or eSIM. When the connectivity management platform queries the subscription status and data quota, the carrier API may return the International Mobile Subscriber Identity (IMSI), which identifies the mobile subscription and must also be masked. The following two subscription records for Germany and the United Kingdom use regions=["DE","GB"] to identify phone numbers and IMSIs. The local part before @ in email addresses is hidden, and the carrier API token uses a keyword rule.
-
Raw data
2026-10-13 09:41:22.075 INFO [connectivity-subscription-service] trace_id=demo-connect-d005 uri=/api/subscriptions/status method=GET cost_ms=34 status=200 { "code": "OK", "subscriptions": [ { "market": "DE", "phone": "+4915700002468", "imsi": "262010000345678", "email": "driver.de@example.com", "sim_status": "ACTIVE", "connection_status": "CONNECTED", "quota_mb": 4096 }, { "market": "GB", "phone": "+447700900123", "imsi": "234100000456789", "email": "driver.gb@example.com", "sim_status": "ACTIVE", "connection_status": "CONNECTED", "quota_mb": 2048 } ], "token": "demo_subscription_token_05" } -
SPL statement
Use the following SPL statement in an ingest processor:
* | extend content = mask(content, '[ {"mode":"buildin","types":["PHONE","IMSI"],"regions":["DE","GB"],"maskType":"placeholder"}, {"mode":"buildin","types":["EMAIL"],"maskType":"anchor","maskBeforeChar":"@"}, {"mode":"keyword","keys":["token"],"maskType":"placeholder"} ]') -
Output
Phone numbers are output as
[PHONE_MASKED], and IMSIs are output as[IMSI_MASKED]. Email addresses useanchorto hide the part before@and keep the domain name. The token is output as the keyword placeholder. The market,sim_status=ACTIVE,connection_status=CONNECTED, and data quota (4096 MB and 2048 MB) of both records keep their original values.regionsselects identification rules. The country where a vehicle is sold is not necessarily the home network of its phone number or IMSI, so check the actual numbers for cross-border connectivity solutions. Support for phone numbers and IMSIs in Germany and the United Kingdom does not mean that all European countries, identity documents, and license plate types are covered. For the supported scope, see "Built-in types and region coverage".
Example 7: Mask vehicle cockpit voice command and large model call logs
The vehicle cockpit sends speech-to-text transcripts to intent recognition or a large model, and then calls tools such as contacts and navigation. The same name and destination may appear repeatedly in the transcript, tool results, and model replies. In the following combined call-and-navigation command, semantic mode identifies Chinese personal names and addresses, buildin mode handles phone numbers and API keys that match the supported formats, and keyword mode handles custom credential keys. The model name, intent, tool status, and latency are kept. The semantic mode is currently supported only in specific regions. The text fields of this log are in Chinese because semantic recognition identifies names and addresses in Chinese natural language.
-
Raw data
{ "time": "2026-10-13T09:48:30.906+08:00", "service": "cockpit-assistant-gateway", "session_id": "session-demo-047", "trace_id": "demo-cockpit-e047", "model": "cockpit-text-model", "intent": "NAVIGATE_AND_CALL", "asr_text": "请给林晨打电话,号码是13600007890,然后导航到杭州市西湖区示例路28号。", "tool_calls": [ { "name": "contacts.lookup", "result_text": "联系人林晨,联系电话13600007890。", "status": "SUCCESS" }, { "name": "navigation.search", "result_text": "目的地为杭州市西湖区示例路28号。", "status": "SUCCESS" } ], "assistant_text": "已找到林晨,将导航至杭州市西湖区示例路28号。", "llm_api_key": "sk-DemoCockpitKeyAbcdef0123456789", "input_tokens": 96, "output_tokens": 27, "cost_ms": 463 } -
SPL statement
Use the following SPL statement in an ingest processor:
* | extend content = mask(content, '[ {"mode":"semantic","types":["NAME","ADDRESS"],"maskType":"placeholder"}, {"mode":"buildin","types":["PHONE","API_KEY"],"maskType":"placeholder"}, {"mode":"keyword","keys":["token","api_key"],"maskType":"placeholder"} ]') -
Output
Names and addresses in
asr_text, bothresult_textfields, andassistant_textare replaced at the positions of the entities, and the phone number and API key are also hidden. The model name, the intentNAVIGATE_AND_CALL, theSUCCESSstatus of both tools, the input and output token counts, and the total latency of 463 ms are kept.
Example 8: Use type labels and masked previews
In logs that contain natural language and mixed text, you may still need to distinguish information types such as phone numbers and credentials after masking, and keep the necessary verification clues. prependPlaceholder:true adds a type label to the result of character masking or anchor-based masking, and the output is typically [TYPE_MASKED]{masked preview}. The following example uses the log in Example 7. Names and addresses are still fully replaced with placeholders. The first 3 and last 4 characters of phone numbers and API keys are kept, and a type label is added.
-
SPL statement
Use the following SPL statement in an ingest processor:
* | extend content = mask(content, '[ {"mode":"semantic","types":["NAME","ADDRESS"],"maskType":"placeholder"}, {"mode":"buildin","types":["PHONE","API_KEY"],"keepPrefix":3,"keepSuffix":4,"prependPlaceholder":true}, {"mode":"keyword","keys":["token","api_key"],"keepPrefix":3,"keepSuffix":4,"prependPlaceholder":true} ]') -
Output
The phone number is output as
[PHONE_MASKED]{136****7890}. You can use[PHONE_MASKED]to determine that the value is a masked phone number, use the kept prefix and suffix to help verify the callee, and then usetrace_idto correlate the call chain. Choose the number of kept characters based on your troubleshooting needs. This parameter also applies to types such as names and addresses. For example, if the semantic rule identifies the name林晨and you setkeepPrefix: 1andprependPlaceholder: true, the output is[NAME_MASKED]{林*}.