-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathaltimate-core-classify-pii.ts
More file actions
51 lines (49 loc) · 2.28 KB
/
altimate-core-classify-pii.ts
File metadata and controls
51 lines (49 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import z from "zod"
import { Tool } from "../../tool/tool"
import { Dispatcher } from "../native"
export const AltimateCoreClassifyPiiTool = Tool.define("altimate_core_classify_pii", {
description:
"Classify PII columns in a schema. Identifies columns likely containing personal identifiable information by name patterns and data types. Provide schema_context or schema_path for accurate table/column resolution.",
parameters: z.object({
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
}),
async execute(args, ctx) {
try {
const result = await Dispatcher.call("altimate_core.classify_pii", {
schema_path: args.schema_path ?? "",
schema_context: args.schema_context,
})
const data = result.data as Record<string, any>
const piiColumns = data.columns ?? data.findings ?? []
const findingCount = piiColumns.length
return {
title: `PII Classification: ${findingCount} finding(s)`,
metadata: { success: result.success, finding_count: findingCount },
output: formatClassifyPii(data),
}
} catch (e) {
const msg = e instanceof Error ? e.message : String(e)
return { title: "PII Classification: ERROR", metadata: { success: false, finding_count: 0 }, output: `Failed: ${msg}` }
}
},
})
function formatClassifyPii(data: Record<string, any>): string {
if (data.error) return `Error: ${data.error}`
const piiColumns = data.columns ?? data.findings ?? []
if (!piiColumns.length) return "No PII columns detected."
const lines: string[] = []
if (data.risk_level) lines.push(`Risk level: ${data.risk_level}`)
if (data.pii_count != null) lines.push(`PII columns: ${data.pii_count} of ${data.total_columns}`)
lines.push("")
lines.push("PII columns found:")
for (const f of piiColumns) {
const classification = f.classification ?? f.category ?? "PII"
const confidence = f.confidence ?? "high"
const table = f.table ?? "unknown"
const column = f.column ?? "unknown"
lines.push(` ${table}.${column}: ${classification} (${confidence} confidence)`)
if (f.suggested_masking) lines.push(` Masking: ${f.suggested_masking}`)
}
return lines.join("\n")
}