←News detail

Tencent Cloud Developer CommunityUpdated Oct 25 21:27

SpringAI Customer Service Security Compliance in Practice: Sensitive Word Filtering, PII Masking, and Conversation Auditing

AI summary

Based on SpringBoot 3.3.x and SpringAI 1.0.x, this article presents a security and compliance solution for launching AI customer service in financial and government/enterprise scenarios: using the DFA algorithm for bidirectional sensitive word filtering, with a 100,000-word lexicon matched within 1ms; using regular expressions to mask phone numbers, ID card numbers, bank card numbers, and email addresses before calling Hunyuan; storing audit logs independently in Tencent Cloud CDB, allowing only INSERT, retaining them for 5 years, and keeping both original and masked records. The solution is designed with reference to Level 3 of the Multi-Level Protection Scheme and the Personal Information Protection Law.

Body · AI translation

Abstract: AI customer service must pass security and compliance checks before going live in financial and government/enterprise scenarios. This article implements a sensitive-word filtering Advisor, PII (personally identifiable information) masking, conversation audit log retention in CDB, and traceable query of records, meeting Level 3 of the Multi-Level Protection Scheme (MLPS) and financial regulatory requirements. After masking, phone numbers/ID card numbers/bank card numbers in user input are replaced with , and the audit log keeps both the original and masked copies, balancing compliance and traceability.

Applicable versions: SpringBoot 3.3.x / SpringAI 1.0.x / Tencent Cloud CDB/CLS / Hunyuan / JDK 17+ I. Background: Security and compliance checks AI customer service must pass before going live

The first 9 articles got the customer service capabilities running, but the security team raised four hard requirements, and without meeting them, it would not be allowed to go live:

Requirement 2: PII masking. Users may enter phone numbers, ID card numbers, and bank card numbers in conversations; this information must not be transmitted in plaintext to Hunyuan (data cross-border risk), nor stored in logs in plaintext.

Requirement 3: Conversation audit trail. Financial regulation requires every customer service conversation to be traceable, with a retention period of ≥ 5 years. Audit logs must not be tampered with and need independent storage.

Requirement 4: Regulatory reporting interface. During regulatory spot checks, complete conversation records must be exportable by time range/user/session.

II. Sensitive-word filtering Advisor 2.1 Sensitive-word dictionary management

[Why this code is needed] The sensitive-word dictionary cannot be hardcoded; it needs to be loaded from CDB and support hot updates. The DFA (deterministic finite automaton) algorithm for sensitive-word matching is 100 times faster than String.contains(), completing matching against a 100,000-word dictionary within 1 ms.

2.2 Sensitive-word filtering Advisor

[Why this code is needed] This is an enhanced version of the Advisor chain from Article 6. Bidirectional filtering of user input and AI replies: intercept user sensitive words at the request stage, and filter sensitive words in AI replies at the response stage. AI replies are generated by the large model; even if constrained by the prompt, they may occasionally produce sensitive words, so post-filtering is mandatory.

III. PII masking: protection of personally identifiable information 3.1 PII identification and masking

[Why this code is needed] Use regular expressions to identify phone numbers/ID card numbers/bank card numbers/emails and replace them with masked formats. Masking is performed before calling Hunyuan, ensuring PII does not leave Tencent Cloud (although the Hunyuan API is within Tencent Cloud, PII masking is a compliance requirement). The audit log keeps both the original and masked copies, balancing compliance and traceability.

3.2 Masking Advisor

[Why this code is needed] The masking Advisor executes after sensitive-word filtering and before calling Hunyuan. The masked message is passed to Hunyuan, so PII does not leave the system. The audit log records both the original message and the masked message; the original message is stored encrypted and can be decrypted and viewed only by authorized personnel.

IV. Conversation audit and traceable records 4.1 Audit log table design

[Why this SQL is needed] The audit table is independent of the conversation history table and meets financial regulatory requirements: tamper-proof (INSERT only), 5-year retention, and support for queries by time/user/session. originalmessage is stored encrypted, while maskedmessage is in plaintext for ordinary queries.

4.2 Traceable record query

[Why this code is needed] During regulatory spot checks, complete conversation records need to be exported by time range. AuditQueryService provides query interfaces by time/user/session, and originalmessage in the returned audit records requires authorized decryption. Export formats support JSON and CSV, meeting regulatory reporting requirements.

--- V. Security and compliance self-check list

VI. Review of all 10 articles in the series

This series built an enterprise intelligent customer service system based on SpringAI + Tencent Cloud from scratch, and the 10 articles form a complete knowledge loop:

| Article | Core technology | Problem solved | Key result | |------|---------|-----------|---------| | 01 | ChatClient + SSE | Streaming conversation + history persistence | First response 8s→1.2s | | 02 | BeanOutputConverter | Intent classification + slot extraction | Accuracy 68%→94% | | 03 | VectorStore + ES | Vector storage + hybrid retrieval | Recall 91% | | 04 | ETL + COS | Automatic document sync | 500 documents imported in 3 minutes | | 05 | ChatMemory | Multi-turn conversation memory | Tokens reduced 78% | | 06 | Advisor chain | Cross-cutting logic orchestration | Code 120 lines→15 lines | | 07 | @Tool | Agent calls work orders | Task completion rate 45%→87% | | 08 | Multi-model routing | Cost optimization | Monthly cost reduced 66% | | 09 | Token governance | Caching + alerting | Monthly cost reduced 79% | | 10 | Security and compliance | Masking + auditing | MLPS Level 3 achieved | Knowledge loop

Tencent Cloud product coverage

| Metric | Before transformation (rule engine) | After transformation (SpringAI+Hunyuan) | Improvement | |------|----------------|---------------------|------| | First response time | 8 seconds | 1.2 seconds | ↓85% | | First-contact resolution rate | 61% | 87% | ↑26pp | | Handoff-to-human rate | 45% | 18% | ↓27pp | | Average daily volume | 3,000 turns | 12,000 turns | 4× | | Monthly Token cost | — | ¥1518 | Controllable | | Security and compliance | Not applicable | MLPS Level 3 achieved | ✅ | VII. Pitfall log Pitfall 1: Matching interruption during hot update of the DFA sensitive-word dictionary

Symptom: When operations updated the sensitive-word dictionary, ongoing conversations occasionally missed sensitive-word checks.

Diagnosis: loadWords() directly replaced the dfaFilter reference, and there was a brief window at the moment of replacement when it was not covered.

Solution: Use volatile to modify the dfaFilter reference, or use AtomicReference to ensure visibility. Perform hot updates during off-peak hours. Pitfall 2: PII regex mistakenly matches order numbers

Symptom: Order number CS20260809001 was matched by the bank card regex [1-9]\d{14,18} and masked to 9001.

Diagnosis: The order number contains 14+ consecutive digits and was mistakenly hit by the bank card regex.

Solution: Exclude known formats (order numbers starting with CS) before PII matching. Or use a more precise bank card regex (with Luhn check):

Pitfall 3: INSERT-only audit table causes Token statistics update to fail

Symptom: The audit table write succeeded, but a subsequent attempt to update the tokensconsumed field reported UPDATE command denied.

Diagnosis: The audit table was set to INSERT-only permission, so any UPDATE was rejected.

Solution: Obtain Token usage from ChatResponse when writing to the audit table, and INSERT the complete record in one go without subsequent UPDATEs. If an update is necessary, use an append-record approach (INSERT a new Token supplementary record). VIII. Series conclusion

From the first Hello World of integrating SpringAI with Hunyuan to production-grade security and compliance auditing, the 10 articles fully cover the entire chain of enterprise intelligent customer service.

Technology selection review: SpringAI 1.0, as Spring's official AI framework, integrates seamlessly with the SpringBoot ecosystem and connects to Hunyuan through an OpenAI-compatible interface, so data does not leave Tencent Cloud. Compared with LangChain4j, it is closer to the Spring philosophy; compared with Tencent Cloud Agent platforms (CodeBuddy/WorkBuddy), it is more flexible and controllable.

Three core lessons: The Advisor chain is the architectural skeleton—all cross-cutting logic (security/rate limiting/RAG/logging) is orchestrated through the Advisor chain, keeping business code clean. Multi-model routing is key to cost—choose pro/standard/lite by complexity, reducing cost by 66%. Security and compliance are prerequisites for going live—sensitive-word filtering/PII masking/audit trails are not optional but mandatory.

As the SpringAI ecosystem matures and Hunyuan capabilities strengthen, this architecture will continue to evolve. But the core methodology—abstraction, orchestration, routing, governance, and compliance—will not become outdated. Authenticity statement: This article is based on actual testing with Tencent Cloud CDB/CLS + Hunyuan. The security and compliance solution is designed with reference to MLPS Level 3 requirements, and the PII masking rules are implemented with reference to the Personal Information Protection Law. Audit table permission control was verified on Tencent Cloud CDB MySQL 8.0. If this article is helpful to you, welcome to like, bookmark, and share it! If you have any questions or suggestions, please leave a comment in the comment section. Follow me to get more SpringAI + Tencent Cloud practical experience! The writing was rushed, so there are surely shortcomings; friends are welcome to criticize and correct in the comments, and I would be deeply grateful!

Source

Tencent Cloud Developer Community