@@ -884,6 +884,67 @@ func (c *Classifier) ClassifyPIIWithThreshold(text string, threshold float32) ([
884884 return result , nil
885885}
886886
887+ // ClassifyPIIWithDetails performs PII token classification and returns full entity details including confidence scores
888+ func (c * Classifier ) ClassifyPIIWithDetails (text string ) ([]PIIDetection , error ) {
889+ return c .ClassifyPIIWithDetailsAndThreshold (text , c .Config .PIIModel .Threshold )
890+ }
891+
892+ // ClassifyPIIWithDetailsAndThreshold performs PII token classification with a custom threshold and returns full entity details
893+ func (c * Classifier ) ClassifyPIIWithDetailsAndThreshold (text string , threshold float32 ) ([]PIIDetection , error ) {
894+ if ! c .IsPIIEnabled () {
895+ return []PIIDetection {}, fmt .Errorf ("PII detection is not properly configured" )
896+ }
897+
898+ if text == "" {
899+ return []PIIDetection {}, nil
900+ }
901+
902+ // Use PII token classifier for entity detection
903+ configPath := fmt .Sprintf ("%s/config.json" , c .Config .PIIModel .ModelID )
904+ start := time .Now ()
905+ tokenResult , err := c .piiInference .ClassifyTokens (text , configPath )
906+ metrics .RecordClassifierLatency ("pii" , time .Since (start ).Seconds ())
907+ if err != nil {
908+ return nil , fmt .Errorf ("PII token classification error: %w" , err )
909+ }
910+
911+ if len (tokenResult .Entities ) > 0 {
912+ logging .Infof ("PII token classification found %d entities" , len (tokenResult .Entities ))
913+ }
914+
915+ // Convert token entities to PII detections, filtering by threshold
916+ var detections []PIIDetection
917+ for _ , entity := range tokenResult .Entities {
918+ if entity .Confidence >= threshold {
919+ detection := PIIDetection {
920+ EntityType : entity .EntityType ,
921+ Start : entity .Start ,
922+ End : entity .End ,
923+ Text : entity .Text ,
924+ Confidence : entity .Confidence ,
925+ }
926+ detections = append (detections , detection )
927+ logging .Infof ("Detected PII entity: %s ('%s') at [%d-%d] with confidence %.3f" ,
928+ entity .EntityType , entity .Text , entity .Start , entity .End , entity .Confidence )
929+ }
930+ }
931+
932+ if len (detections ) > 0 {
933+ // Log unique PII types for compatibility with existing logs
934+ uniqueTypes := make (map [string ]bool )
935+ for _ , d := range detections {
936+ uniqueTypes [d .EntityType ] = true
937+ }
938+ types := make ([]string , 0 , len (uniqueTypes ))
939+ for t := range uniqueTypes {
940+ types = append (types , t )
941+ }
942+ logging .Infof ("Detected PII types: %v" , types )
943+ }
944+
945+ return detections , nil
946+ }
947+
887948// DetectPIIInContent performs PII classification on all provided content
888949func (c * Classifier ) DetectPIIInContent (allContent []string ) []string {
889950 var detectedPII []string
0 commit comments