From 6c503a8c911d804f86f057758225fa05b86c4b99 Mon Sep 17 00:00:00 2001 From: shahriar654 Date: Mon, 27 Jul 2026 17:04:49 +0600 Subject: [PATCH] fix: prevent CitationMixin crash when context missing 'context' key (#2459) --- instructor/v2/dsl/citation.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/instructor/v2/dsl/citation.py b/instructor/v2/dsl/citation.py index c5ccd4f04..3aa044f00 100644 --- a/instructor/v2/dsl/citation.py +++ b/instructor/v2/dsl/citation.py @@ -69,6 +69,9 @@ def validate_sources(self, info: ValidationInfo) -> "CitationMixin": # Get the context from the info text_chunks = info.context.get("context", None) + if text_chunks is None: + return self + # Get the spans of the substring_phrase in the context spans = list(self.get_spans(text_chunks)) # Replace the substring_phrase with the actual substring