Skip to content

Commit ed2d642

Browse files
authored
Investigate instructor client import errors (#1818)
fix: re-expose instructor.client for backward compatibility ## Describe your changes This PR addresses the critical breaking change where `instructor.client` was no longer directly accessible, causing `AttributeError` for users. The changes re-expose `client` in `instructor/__init__.py` to restore backward compatibility, allowing `instructor.client.Instructor` and `instructor.client.AsyncInstructor` to function again. Deprecation warnings are in place to guide users towards the new direct import paths. Additionally, an internal reference in `instructor/providers/writer/client.py` was updated for consistency. ## Issue ticket number and link #1816 ## Checklist before requesting a review - [ ] I have performed a self-review of my code - [ ] If it is a core feature, I have added thorough tests. - [ ] If it is a core feature, I have added documentation. --- [Slack Thread](https://567-studio.slack.com/archives/C08U5CAP8KV/p1758785426626979?thread_ts=1758785426.626979&cid=C08U5CAP8KV) <a href="https://cursor.com/background-agent?bcId=bc-4c062dcf-ca79-46b8-b16e-dcc5bbf1b509"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/open-in-cursor-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/open-in-cursor-light.svg"><img alt="Open in Cursor" src="https://cursor.com/open-in-cursor.svg"></picture></a>&nbsp;<a href="https://cursor.com/agents?id=bc-4c062dcf-ca79-46b8-b16e-dcc5bbf1b509"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/open-in-web-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/open-in-web-light.svg"><img alt="Open in Web" src="https://cursor.com/open-in-web.svg"></picture></a> <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Re-expose `instructor.client` for backward compatibility and update internal references in `from_writer()`. > > - **Behavior**: > - Re-expose `client` in `instructor/__init__.py` for backward compatibility, allowing `instructor.client.Instructor` and `instructor.client.AsyncInstructor` to work. > - Add deprecation warnings to guide users to new import paths. > - **Internal References**: > - Update return type in `from_writer()` in `instructor/providers/writer/client.py` to use `instructor.Instructor` and `instructor.AsyncInstructor` directly. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=567-labs%2Finstructor&utm_source=github&utm_medium=referral)<sup> for 91245da. You can [customize](https://app.ellipsis.dev/567-labs/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
2 parents c785db2 + 91245da commit ed2d642

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

instructor/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,16 @@
6363
"llm_validator",
6464
"openai_moderation",
6565
"hooks",
66+
"client", # Backward compatibility
6667
# Backward compatibility exports
6768
"handle_response_model",
6869
"handle_parallel_model",
6970
]
7071

72+
# Backward compatibility: Make instructor.client available as an attribute
73+
# This allows code like `instructor.client.Instructor` to work
74+
from . import client
75+
7176

7277
if importlib.util.find_spec("anthropic") is not None:
7378
from .providers.anthropic.client import from_anthropic

instructor/providers/writer/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def from_writer(
2727
client: Writer | AsyncWriter,
2828
mode: instructor.Mode = instructor.Mode.WRITER_TOOLS,
2929
**kwargs: Any,
30-
) -> instructor.client.Instructor | instructor.client.AsyncInstructor:
30+
) -> instructor.Instructor | instructor.AsyncInstructor:
3131
valid_modes = {instructor.Mode.WRITER_TOOLS, instructor.Mode.WRITER_JSON}
3232

3333
if mode not in valid_modes:

0 commit comments

Comments
 (0)