Skip to content

The agent engineering platform.

community[patch]: avoid KeyError when language not in LANGUAGE_SEGMENTERS (#15212)

bachrb3ed98dec070
diff --git a/libs/community/langchain_community/document_loaders/parsers/language/language_parser.py b/libs/community/langchain_community/document_loaders/parsers/language/language_parser.py
index c53dd493fd..b3f6534327 100644
--- a/libs/community/langchain_community/document_loaders/parsers/language/language_parser.py
+++ b/libs/community/langchain_community/document_loaders/parsers/language/language_parser.py
@@ -97,6 +97,8 @@ class LanguageParser(BaseBlobParser):
language: If None (default), it will try to infer language from source.
parser_threshold: Minimum lines needed to activate parsing (0 by default).
"""
+ if language and language not in LANGUAGE_SEGMENTERS:
+ raise Exception(f"No parser available for {language}")
self.language = language
self.parser_threshold = parser_threshold