feat(v2): PR 4/7 - GenAI, Cohere, and Mistral providers#2021
feat(v2): PR 4/7 - GenAI, Cohere, and Mistral providers#2021jxnl wants to merge 2 commits intofeat/v2-pr3-anthropic-openaifrom
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
instructor | bf8f011 | Commit Preview URL Branch Preview URL |
Jan 18 2026, 06:55 PM |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| ) | ||
| + "\n" | ||
| ) | ||
| # endregion agent log |
There was a problem hiding this comment.
Debug logging code writes to hardcoded local path
High Severity
The from_cohere function contains debug logging code that writes to a hardcoded local path /Users/jasonliu/dev/instructor/.cursor/debug.log. This code attempts to open a file on every call to create a Cohere client. On any machine without this exact directory structure, this will raise a FileNotFoundError, causing the entire from_cohere function to fail. The code block is marked with # region agent log comments indicating it was temporary debugging code that was accidentally included in the commit.
| # Add instruction based on client version | ||
| if "messages" in new_kwargs: | ||
| # V2 format: prepend to messages | ||
| new_kwargs["messages"].insert(0, {"role": "user", "content": instruction}) |
There was a problem hiding this comment.
Shallow copy causes mutation of caller's kwargs messages
Medium Severity
The handlers use kwargs.copy() (shallow copy) then mutate nested objects like kwargs["messages"].insert(), append(), or extend(). Since shallow copy shares references to nested objects, these mutations affect the original kwargs passed by the caller. The test file acknowledges this with the comment "messages list is modified in place though". If callers reuse kwargs across multiple requests, instructions and messages will accumulate unexpectedly.
Additional Locations (2)
| elif messages and isinstance(messages[0]["content"], str): | ||
| messages[0]["content"] += f"\n\n{message}" | ||
| elif messages and isinstance(messages[0]["content"], list): | ||
| messages[0]["content"][0]["text"] += f"\n\n{message}" |
There was a problem hiding this comment.
Missing empty list check causes IndexError on multimodal content
Low Severity
In MistralMDJSONHandler.prepare_request, the code checks isinstance(messages[0]["content"], list) but doesn't verify the list is non-empty before accessing messages[0]["content"][0]["text"]. If a message has an empty content list (valid in multimodal formats), this raises an IndexError when trying to access index 0 of an empty list.
d0469c0 to
921ae4f
Compare
e2f8e06 to
0de415d
Compare
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
0de415d to
b44fa73
Compare
921ae4f to
233934e
Compare
b44fa73 to
26bcb47
Compare
233934e to
df648e9
Compare
- Add instructor/v2/providers/genai/ with handlers for TOOLS, JSON modes - Add instructor/v2/providers/cohere/ with handlers for TOOLS, JSON_SCHEMA, MD_JSON modes - Add instructor/v2/providers/mistral/ with handlers for TOOLS, JSON_SCHEMA, MD_JSON modes - Update instructor/v2/__init__.py with from_genai, from_cohere, from_mistral exports - Add tests/v2/test_genai_integration.py - Add tests/v2/test_cohere_handlers.py - Add tests/v2/test_mistral_client.py and test_mistral_handlers.py This PR was written by [Cursor](https://cursor.com)
df648e9 to
9e715eb
Compare
- Remove debug logging in Cohere client - Fix shallow copy mutation in Cohere handlers (copy messages list) - Add empty list check in Mistral MD_JSON handler

Description
This is PR 4 of 7 in the stacked PR series implementing Instructor V2 registry-based architecture.
Base: PR 3 (feat/v2-pr3-anthropic-openai)
Providers Added
GenAI (
instructor/v2/providers/genai/)TOOLS,JSONsafety_settingscorrectly, supports cached contentCohere (
instructor/v2/providers/cohere/)TOOLS,JSON_SCHEMA,MD_JSONCOHERE_TOOLS->TOOLS,COHERE_JSON_SCHEMA->JSON_SCHEMAMistral (
instructor/v2/providers/mistral/)TOOLS,JSON_SCHEMA,MD_JSONMISTRAL_TOOLS->TOOLS,MISTRAL_STRUCTURED_OUTPUTS->JSON_SCHEMAChanges
instructor/v2/providers/genai/(3 files)instructor/v2/providers/cohere/(3 files)instructor/v2/providers/mistral/(3 files)instructor/v2/__init__.pywith provider exportsTesting
Stacked PRs
This PR was written by Cursor
Note
Adds three new providers to the v2 registry architecture with client factories and mode handlers, plus exports and tests.
from_genai,from_cohere,from_mistralwith sync/async wrappers, streaming support, and default model injection where applicable; updateinstructor/v2/__init__.pyexportsTOOLS,JSONwith system/config mapping, multimodal content conversion, streamingPartialsupport, and legacy mode mappingTOOLS,JSON_SCHEMA,MD_JSONwith V1 (chat_history/message) and V2 (messages) format handling, response parsing, and re-ask flowsTOOLS,JSON_SCHEMA,MD_JSONadapting tochat.complete/stream, tool_choice="any", schema/markdown parsing, and dict/string tool argsWritten by Cursor Bugbot for commit d0469c0. Configure here.