Repository navigation
Conversation
_get_instructor_client() passed the effective mode to instructor.from_openai, instructor.from_litellm and the generic provider patcher, but called instructor.from_anthropic, instructor.from_genai and instructor.from_gemini without it. A caller-supplied mode - and the documented Mode.JSON default - was therefore silently ignored for provider="anthropic"/"google"/"gemini", leaving the patched client on instructor's own default (Mode.TOOLS for the anthropic and google-genai adapters). The mode is now forwarded in all three branches, and the default is made provider-aware: google-generativeai supports only TOOLS and MD_JSON, so it keeps Mode.MD_JSON rather than the Mode.JSON default used elsewhere.
This branch has not been deployed
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.
Issue Link / Problem Description
mode=is silently discarded for provider='anthropic' and provider='google'/'gemini' (new google-genai) #3021llm_factory(..., mode=...)documentsmodeas the instructor mode for structured output (defaultMode.JSON), and_get_instructor_client()normalizesNonetoMode.JSON. That normalized value was only forwarded to some branches —instructor.from_openai(client, mode=mode),instructor.from_litellm(client, mode=mode)and_patch_client_for_provider(..., mode=mode)— while the anthropic and google branches calledinstructor.from_anthropic(client),instructor.from_genai(client)andinstructor.from_gemini(client)with nomodeargument. The mode was accepted and then discarded, so the patched client stayed on instructor's own per-factory default (Mode.TOOLSforfrom_anthropicandfrom_genai,Mode.MD_JSONforfrom_gemini) instead of the requested — and documented-default —Mode.JSON.Root cause, unpatched
src/ragas/llms/base.py: the effective mode is computed at lines 584-585 but lines 591, 594 and 596 call the three factories without it.Changes Made
src/ragas/llms/base.py: forwardmodetoinstructor.from_anthropic,instructor.from_genaiandinstructor.from_gemini, matching the existingfrom_openai/from_litellmbranches.src/ragas/llms/base.py: make theNonedefault provider-aware.google-generativeai(old SDK) has no JSON mode — instructor supports onlyMode.TOOLSandMode.MD_JSONfor it and raisesModeError: Invalid mode 'json_mode' for provider 'gemini'. Valid modes: markdown_json_mode, tool_call— so a defaulted mode resolves toMode.MD_JSONfor that client, which is what it already got via instructor's own default. Without this, forwarding the normalizedMode.JSONwould turn the working default path into a hard error. An explicitly requested mode is always forwarded, so an unsupported explicit request now fails loudly in instructor instead of being ignored.tests/unit/llms/test_instructor_factory.py: addtest_llm_factory_mode_reaches_provider_factories, covering both an explicitly requested mode and the default forprovider="anthropic","google"(new google-genai client) and"gemini"(old SDK client).Not changed:
provider="perplexity"also ignoresmode, but instructor's perplexity provider supports onlyMode.MD_JSON, which is its own default, so forwarding the normalizedMode.JSONthere would raiseModeErrorrather than fix anything.Testing
How to Test
New test on the unpatched tree (
src/ragas/llms/base.pyatmain298b682, test kept):On the patched tree:
Unmodified
mainreports the identical failure/error set (3 failed, 741 passed, 62 skipped, 8 errors); the only difference is the added test. The pre-existing failures are missing optionalsacrebleu/haystackdependencies andtest_experiment.pygit fixtures.Lint and types:
ruff format --checkandruff checkpass on both changed files (the repo-wideruff format --checkreports 88 pre-existing reformats in files this PR does not touch);ruff check src tests docspasses repo-wide;pyright -p pyproject.toml srcreports its 6 pre-existingModule is not callableerrors insrc/ragas/integrations/*and 0 errors insrc/ragas/llms/base.py.Local run note (environment only, not part of the diff):
import ragascurrently fails onmainwithlangchain-community0.4.x, becausesrc/ragas/llms/base.py:12importslangchain_community.chat_models.vertexaiunconditionally and that module no longer exists. I pinnedlangchain-community==0.3.31in a local venv to run the suite; this PR does not touch that separate breakage.References
mode=is silently discarded for provider='anthropic' and provider='google'/'gemini' (new google-genai) #3021from_anthropicsupportsTOOLS/JSON/JSON_SCHEMA/PARALLEL_TOOLS(defaultTOOLS);from_genaisupportsTOOLS/JSON(defaultTOOLS);from_geminisupportsTOOLS/MD_JSON(defaultMD_JSON).Mode.JSONis the documented default for OpenAI.Screenshots/Examples (if applicable)
N/A — argument forwarding plus a provider-aware default.