fix: declare regex as a core dependency (CitationMixin crashes with ModuleNotFoundError)#2443
Open
chuenchen309 wants to merge 1 commit into
Open
Conversation
…Error) instructor/v2/dsl/citation.py's CitationMixin._get_span does `import regex` at call time, but `regex` is not declared anywhere in pyproject.toml's core dependencies or any optional-dependencies extra (checked all ~25 extras). A stock `pip install instructor` therefore has CitationMixin -- a documented public feature -- crash with ModuleNotFoundError the moment validate_sources() runs, i.e. the feature is entirely broken on a clean install. This isn't a hypothetical: the repo's own existing test tests/coverage/test_dsl_small_coverage.py::test_citation_keeps_quotes_without_context_and_recovers_fuzzy_quotes already exercises this path and fails on a stock checkout without `regex` manually installed. Fix: add "regex>=2023.0.0" to [project.dependencies] and update uv.lock accordingly. Not a duplicate of 567-labs#2430 (open, "fix(citations): escape substring quotes before fuzzy span matching") -- that PR fixes a different bug (regex.error on quotes containing metacharacters) and does not touch pyproject.toml; its own new test uses pytest.importorskip("regex"), i.e. it works around this exact missing-dependency issue rather than fixing it. Testing: previously-failing test now passes (16/16 in test_dsl_small_coverage.py); full tests/dsl/ + test_dsl_small_coverage.py suite (88 passed, 2 pre-existing skips unrelated to this change); ruff clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ErenAta16
approved these changes
Jul 14, 2026
ErenAta16
left a comment
There was a problem hiding this comment.
Checked where regex is actually used: it's a local import regex inside CitationMixin's fuzzy-match method in instructor/v2/dsl/citation.py, not a module-level import, so strictly only the fuzzy-citation path needs it, not every CitationMixin user. Declaring it as a core dependency rather than gating it behind a lazy import or an extras group is still the right call here: regex is small and has no heavy transitive dependencies, and the alternative (lazy-guarded import with a custom error message) would be more code for a package this lightweight. Straightforward fix for a real crash.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CitationMixin._get_span(instructor/v2/dsl/citation.py:81) doesimport regexat call time, butregexis not declared anywhere inpyproject.toml's coredependenciesor any[project.optional-dependencies]extra (checked all ~25 extras — none of them pull it in).A stock
pip install instructortherefore hasCitationMixin— a documented public feature — crash withModuleNotFoundErrorthe momentvalidate_sources()runs. The feature is entirely broken on a clean install.This isn't hypothetical: the repo's own existing test
tests/coverage/test_dsl_small_coverage.py::test_citation_keeps_quotes_without_context_and_recovers_fuzzy_quotesalready exercises this exact path and fails on a fresh checkout withoutregexmanually installed.Fix
Add
"regex>=2023.0.0"to[project.dependencies]and updateuv.lockaccordingly.Not a duplicate of #2430
#2430 ("fix(citations): escape substring quotes before fuzzy span matching", open) fixes a different bug —
regex.erroron quotes containing metacharacters — and does not touchpyproject.toml. Its own new test usespytest.importorskip("regex"), i.e. it works around this exact missing-dependency issue rather than fixing it. Both fixes are needed independently.Testing
test_dsl_small_coverage.py.tests/dsl/+test_dsl_small_coverage.py: 88 passed, 2 pre-existing skips (unrelated to this change).ruff checkclean.AI-Generated disclosure
Found via an AI-assisted code review pass (Claude Code) over
instructor/v2/dsl/. I personally reproduced theModuleNotFoundErroragainst the repo's own pre-existing test, verified the fix, checked for overlap with #2430, and ran the relevant test suites before submitting.