Coverage for presidio_analyzer / predefined_recognizers / country_specific / germany / de_vat_id_recognizer.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-03-29 09:03 +0000

1from typing import List, Optional 

2 

3from presidio_analyzer import Pattern, PatternRecognizer 

4 

5 

6class DeVatIdRecognizer(PatternRecognizer): 

7 """ 

8 Recognizes German Umsatzsteuer-Identifikationsnummer (USt-IdNr.). 

9 

10 The USt-IdNr. is issued by the Bundeszentralamt für Steuern (BZSt) to 

11 VAT-registered businesses and self-employed persons in Germany. It is 

12 used on invoices and cross-border EU transactions. While primarily a 

13 business identifier, it can identify sole traders and freelancers (natural 

14 persons) and may therefore constitute personal data under DSGVO Art. 4 

15 Nr. 1 when linked to an individual. 

16 

17 Legal basis: § 27a UStG (Umsatzsteuergesetz). 

18 Format documentation: BZSt (Bundeszentralamt für Steuern). 

19 Data protection: DSGVO Art. 4 Nr. 1 (if linked to a natural person), BDSG. 

20 

21 Format (11 characters): 

22 "DE" + 9 digits 

23 

24 Examples (fictitious): DE123456789, DE987654321 

25 

26 Accuracy note: The fixed ``DE`` prefix makes this pattern very specific 

27 with a very low false-positive rate. Formal legal validity is confirmed 

28 via the BZSt/EU VAT verification service, not by local format checks. 

29 No formal accuracy evaluation has been performed on a labelled dataset. 

30 

31 :param patterns: List of patterns to be used by this recognizer 

32 :param context: List of context words to increase confidence in detection 

33 :param supported_language: Language this recognizer supports 

34 :param supported_entity: The entity this recognizer can detect 

35 """ 

36 

37 PATTERNS = [ 

38 Pattern( 

39 "Umsatzsteuer-Identifikationsnummer USt-IdNr. (DE + 9 digits)", 

40 r"\bDE\d{9}\b", 

41 0.5, 

42 ), 

43 ] 

44 

45 CONTEXT = [ 

46 "umsatzsteuer-identifikationsnummer", 

47 "umsatzsteueridentifikationsnummer", 

48 "ust-idnr", 

49 "ust-id", 

50 "ustidnr", 

51 "umsatzsteuer-id", 

52 "mehrwertsteuer", 

53 "vat", 

54 "vat-id", 

55 "vat id", 

56 "steueridentifikation", 

57 "bzst", 

58 "bundeszentralamt für steuern", 

59 "finanzamt", 

60 "invoice", 

61 "rechnung", 

62 ] 

63 

64 def __init__( 

65 self, 

66 patterns: Optional[List[Pattern]] = None, 

67 context: Optional[List[str]] = None, 

68 supported_language: str = "de", 

69 supported_entity: str = "DE_VAT_ID", 

70 name: Optional[str] = None, 

71 ): 

72 patterns = patterns if patterns else self.PATTERNS 

73 context = context if context else self.CONTEXT 

74 super().__init__( 

75 supported_entity=supported_entity, 

76 patterns=patterns, 

77 context=context, 

78 supported_language=supported_language, 

79 name=name, 

80 )