#1596·guardrails

langchain-core is a core dependency but only needs to be an extra

Author: zsimjeeCreated Jul 24, 2026Updated Sep 26, 2026
LabelsStale

langchain-core>=1.0.0,<2.0 is a core dependency (pyproject.toml:31), so import guardrails hard-requires LangChain. It doesn't need to.

Contrast with our other framework integrations, which are already correct: integrations/__init__.py is empty, the top-level guardrails/__init__.py never imports integrations, each module guards its third-party imports in try/except ImportError with an install hint, and the deps live in the optional llama / databricks extras. The code ships; the dependency doesn't get installed unless asked for.

LangChain is core only because three annotations were written as eager top-level imports, in modules that always load (guardrails/__init__.py imports both guard and validator_base):

Site Import Why it's unnecessary
guard.py:20 from langchain_core.runnables import Runnable Used only as the return annotation of to_runnable(); the real construction at :1072 is already a lazy import
validator_base.py:21 from langchain_core.runnables import Runnable Same — lazy import already present at :503
classes/input_type.py:3 from langchain_core.messages import BaseMessage Only feeds InputType = TypeVar("InputType", str, BaseMessage), whose sole consumer is integrations/langchain/base_runnable.py

Fix

  1. Move both Runnable imports under if TYPE_CHECKING: and quote the return annotations (-> "Runnable"). No runtime behavior change — to_runnable() already raises from its lazy import path when LangChain is absent, matching llama_index DX.
  2. Move InputType into guardrails/integrations/langchain/, where its only consumer lives. InputType is a plain TypeVar with no Pydantic runtime role, so this is a pure relocation.
  3. Move langchain-core from core dependencies to a langchain extra, alongside llama and databricks.

Note

InputType is currently re-exported from guardrails.classes.__all__ (classes/__init__.py:2,15), so step 2 is a small public-API removal — worth a release-note line.

Independent of the 1.0 work and low-risk; could land on its own.

Source: guardrails-ai/guardrails