Skip to content

Commit c1f7350

Browse files
throwing import error if nltk not available in detect_pii mock
1 parent e699397 commit c1f7350

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tests/integration_tests/test_assets/validators/detect_pii.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import Any, Callable, Dict, List, Union
22
import difflib
3-
import nltk
43

54
from guardrails.validator_base import (
65
FailResult,
@@ -65,6 +64,14 @@ def chunking_function(self, chunk: str):
6564
Because using the tokenizer is expensive, we only use it if
6665
there is a period present in the chunk.
6766
"""
67+
try:
68+
import nltk
69+
except ImportError:
70+
raise ImportError(
71+
"nltk is required for sentence splitting. Please install it using "
72+
"`poetry add nltk`"
73+
)
74+
6875
# using the sentence tokenizer is expensive
6976
# we check for a . to avoid wastefully calling the tokenizer
7077
if "." not in chunk:

0 commit comments

Comments
 (0)