Home / Function/ test_error_callback() — langchain Function Reference

test_error_callback() — langchain Function Reference

Architecture documentation for the test_error_callback() function in test_base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  2fad8f8f_2958_4269_954d_d649c16f2986["test_error_callback()"]
  4404310a_b16c_e9e6_1de2_90e5ea6f3ce3["test_base.py"]
  2fad8f8f_2958_4269_954d_d649c16f2986 -->|defined in| 4404310a_b16c_e9e6_1de2_90e5ea6f3ce3
  4eb3597b_cd31_3217_d338_232d8bfc3f0c["_call()"]
  2fad8f8f_2958_4269_954d_d649c16f2986 -->|calls| 4eb3597b_cd31_3217_d338_232d8bfc3f0c
  9b690729_3e5e_0bb8_1c38_33667ca8a30f["_llm_type()"]
  2fad8f8f_2958_4269_954d_d649c16f2986 -->|calls| 9b690729_3e5e_0bb8_1c38_33667ca8a30f
  style 2fad8f8f_2958_4269_954d_d649c16f2986 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/language_models/llms/test_base.py lines 100–134

async def test_error_callback() -> None:
    class FailingLLMError(Exception):
        """FailingLLMError."""

    class FailingLLM(LLM):
        @property
        def _llm_type(self) -> str:
            """Return type of llm."""
            return "failing-llm"

        @override
        def _call(
            self,
            prompt: str,
            stop: list[str] | None = None,
            run_manager: CallbackManagerForLLMRun | None = None,
            **kwargs: Any,
        ) -> str:
            raise FailingLLMError

    def eval_response(callback: BaseFakeCallbackHandler) -> None:
        assert callback.errors == 1
        assert len(callback.errors_args) == 1
        assert isinstance(callback.errors_args[0]["args"][0], FailingLLMError)

    llm = FailingLLM()
    cb_async = FakeAsyncCallbackHandler()
    with pytest.raises(FailingLLMError):
        await llm.ainvoke("Dummy message", config={"callbacks": [cb_async]})
    eval_response(cb_async)

    cb_sync = FakeCallbackHandler()
    with pytest.raises(FailingLLMError):
        llm.invoke("Dummy message", config={"callbacks": [cb_sync]})
    eval_response(cb_sync)

Subdomains

Frequently Asked Questions

What does test_error_callback() do?
test_error_callback() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/language_models/llms/test_base.py.
Where is test_error_callback() defined?
test_error_callback() is defined in libs/core/tests/unit_tests/language_models/llms/test_base.py at line 100.
What does test_error_callback() call?
test_error_callback() calls 2 function(s): _call, _llm_type.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free