Text Review
Build reviewable obfuscation flows where users can edit replacements before finalizing a session.
Overview
The text review API lets you separate detection from final obfuscation. Instead of calling obfuscate() immediately, you can create a review model, edit replacements, remove items, add manual entities, preview the result, and only then finalize a session.
This is useful for:
- review screens before sending content to an LLM
- legal or medical workflows that need operator approval
- admin tools where users want to override generated replacements
Basic flow
import { PrivacyClient } from '@secured-ai/core'
const client = new PrivacyClient({
baseUrl: 'https://dev-api.securedai.com',
sdkAccessToken: import.meta.env.VITE_SECURED_SDK_ACCESS_TOKEN,
})
const text = 'Customer John Doe can be reached at john@example.com.'
const detection = await client.detect(text)
const review = client.createTextReview(text, detection.sensitiveEntities)At this stage you have a TextReview object with grouped review items rather than a finalized session.
Editing review items
Each item can be updated independently:
const edited = client.setTextReviewReplacement(
review,
review.items[0].id,
'Casey Hart',
)You can also remove and restore items:
const withoutName = client.removeTextReviewItem(edited, edited.items[0].id)
const restored = client.restoreTextReviewItem(withoutName, withoutName.items[0].id)Adding manual entities
If your UI lets a reviewer select text that was missed during automatic detection, add it manually:
const expanded = client.addTextReviewEntity(
review,
{
text: 'john@example.com',
start: 37,
end: 53,
confidence: 0.99,
type: 'EMAIL',
source: 'manual-selection',
},
'masked@example.com',
)Preview before finalization
Use previewTextReview() to render a live preview without creating a persisted session:
const preview = client.previewTextReview(expanded)
console.log(preview.processedText)
console.log(preview.hasSensitiveData)Finalize and create a session
When the user approves the result, finalize it:
const finalized = client.finalizeTextReview(expanded)
console.log(finalized.processedText)
console.log(finalized.sessionId)
console.log(finalized.mappings)
console.log(finalized.serializedSession)finalizeTextReview() returns:
processedTextentitiesmappingssessionIdsessionserializedSessionhasSensitiveData
It also stores the new session on the client, so you can use normal restore() flows afterward.
Grouping behavior
Review items are grouped by normalized entity text and type. If the same name appears multiple times, the review model keeps one item with multiple occurrences so you can edit the replacement once and apply it everywhere consistently.
React integration
If you are using @secured-ai/react, the useTextReview() hook wraps this lifecycle and exposes React state for review, preview, and lastFinalized.