{"record":{"id":"341c2cdb262b7899","repo":"headroomlabs-ai/headroom","slug":"langchain-is-required-for-this-integration-instal-341c2c","errorCode":null,"errorMessage":"LangChain is required for this integration. Install with: pip install headroom[langchain] or: pip install langchain-core","messagePattern":"LangChain is required for this integration\\. Install with: pip install headroom\\[langchain\\] or: pip install langchain-core","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"headroom/integrations/langchain/langsmith.py","lineNumber":73,"sourceCode":"    BaseCallbackHandler = object  # type: ignore[misc,assignment]\n    LLMResult = object  # type: ignore[misc,assignment]\n\n# LangSmith imports - optional\ntry:\n    from langsmith import Client as LangSmithClient\n\n    LANGSMITH_AVAILABLE = True\nexcept ImportError:\n    LANGSMITH_AVAILABLE = False\n    LangSmithClient = None  # type: ignore[misc,assignment]\n\nlogger = logging.getLogger(__name__)\n\n\ndef _check_langchain_available() -> None:\n    \"\"\"Raise ImportError if LangChain is not installed.\"\"\"\n    if not LANGCHAIN_AVAILABLE:\n        raise ImportError(\n            \"LangChain is required for this integration. \"\n            \"Install with: pip install headroom[langchain] \"\n            \"or: pip install langchain-core\"\n        )\n\n\n@dataclass\nclass PendingMetrics:\n    \"\"\"Metrics pending attachment to a LangSmith run.\"\"\"\n\n    tokens_before: int\n    tokens_after: int\n    tokens_saved: int\n    savings_percent: float\n    transforms_applied: list[str]\n    timestamp: datetime = field(default_factory=datetime.now)\n\n","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/integrations/langchain/langsmith.py#L55-L91","documentation":"Raised by _check_langchain_available() in the LangSmith telemetry integration when LANGCHAIN_AVAILABLE is False. Note this module separately tracks LANGSMITH_AVAILABLE; this particular error fires specifically when langchain-core itself is missing, blocking the PendingMetrics/run-annotation machinery that attaches token-savings metrics to LangSmith runs.","triggerScenarios":"Initializing or using the Headroom LangSmith observer/bridge (attaching compression metrics like tokens_before/tokens_after to LangSmith runs) in an environment without langchain-core installed.","commonSituations":"Installing the `langsmith` package alone and assuming that suffices — this integration also requires langchain-core; monitoring setups added after the fact to an app that never depended on LangChain; partial extras installs.","solutions":["Install `pip install 'headroom[langchain]'` or `pip install langchain-core`","If you only need LangSmith and have the standalone langsmith SDK, verify langchain-core is also present (`python -c \"import langchain_core\"`) since this guard requires it","Re-run the observer setup after install"],"exampleFix":"# before\nobserver = HeadroomLangSmithObserver(...)  # raises at first use without langchain-core\n\n# after\n# pip install langchain-core langsmith\nobserver = HeadroomLangSmithObserver(...)","handlingStrategy":"validation","validationCode":"import importlib.util\nassert importlib.util.find_spec('langchain_core'), 'langchain-core required for LangSmith metrics attachment'","typeGuard":"def langsmith_bridge_ready() -> bool:\n    from headroom.integrations.langchain import langsmith\n    return langsmith.LANGCHAIN_AVAILABLE and langsmith.LANGSMITH_AVAILABLE","tryCatchPattern":"try:\n    observer.attach(run)\nexcept ImportError as e:\n    logger.warning('Skipping LangSmith metrics: %s', e)","preventionTips":["Treat telemetry as optional: catch ImportError and continue without metrics","Install langchain-core alongside langsmith, not langsmith alone","Smoke-test the observer in a pre-deploy check"],"tags":["langsmith","langchain","telemetry","import-error"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}