diff --git a/instructor/__init__.py b/instructor/__init__.py index 60b325d81..80b46b2a7 100644 --- a/instructor/__init__.py +++ b/instructor/__init__.py @@ -1,6 +1,7 @@ import importlib.util from .mode import Mode +from .utils import set_env_variable from .process_response import handle_response_model from .distil import FinetuneFormat, Instructions from .dsl import ( @@ -22,6 +23,7 @@ Provider, ) +set_env_variable() __all__ = [ "Instructor", diff --git a/instructor/utils.py b/instructor/utils.py index 9f9448ed4..7eb672db4 100644 --- a/instructor/utils.py +++ b/instructor/utils.py @@ -1,6 +1,7 @@ from __future__ import annotations import inspect +import os import json import logging from collections.abc import AsyncGenerator, Generator, Iterable @@ -209,3 +210,7 @@ def __init__(self, method: Callable[[Any], R_co]) -> None: def __get__(self, instance: object, cls: type[Any]) -> R_co: return self.cproperty(cls) + + +def set_env_variable(): + os.environ["PYDANTIC_ERRORS_INCLUDE_URL"] = "0" diff --git a/tests/test_function_calls.py b/tests/test_function_calls.py index 07b2dc1da..0a0dba4c5 100644 --- a/tests/test_function_calls.py +++ b/tests/test_function_calls.py @@ -1,4 +1,4 @@ -from typing import TypeVar +from typing import TypeVar, List import pytest from anthropic.types import Message, Usage @@ -186,3 +186,16 @@ def test_control_characters_allowed_in_anthropic_json_non_strict_mode( mock_anthropic_message, mode=instructor.Mode.ANTHROPIC_JSON, strict=False ) assert test_model_instance.data == "Claude likes\ncontrol\ncharacters" + + +def test_pylance_url_config() -> None: + class Model(BaseModel): + list_of_ints: List[int] = None + a_float: float = None + + data = dict(list_of_ints=["1", 2, "bad"], a_float="Not a float") + + try: + Model(**data) + except ValidationError as e: + assert "https://errors.pydantic.dev" not in str(e)