{"library":"langchain-anthropic","title":"LangChain Anthropic","description":"LangChain Anthropic is an integration package that connects Anthropic's generative AI models (like Claude) with the LangChain framework. It allows developers to easily incorporate Anthropic's powerful chat models and (legacy) text completion models into their LangChain-based applications. As part of the broader LangChain ecosystem, it follows a frequent release cadence, often aligning with updates to `langchain-core` and the main `langchain` library. The current version is 1.4.0.","status":"active","version":"1.4.0","language":"en","source_language":"en","source_url":"https://github.com/langchain-ai/langchain","tags":["langchain","llm","anthropic","claude","chatbots","ai","generative-ai"],"install":[{"cmd":"pip install langchain-anthropic","lang":"bash","label":"Install package"}],"dependencies":[{"reason":"Required for interacting with Anthropic's API.","package":"anthropic","optional":false},{"reason":"Used for data validation and settings management within LangChain components.","package":"pydantic","optional":false},{"reason":"Core abstractions and foundational components of LangChain.","package":"langchain-core","optional":false}],"imports":[{"note":"This is the recommended class for interacting with Anthropic's chat models (e.g., Claude 3, Claude 2.1).","symbol":"ChatAnthropic","correct":"from langchain_anthropic import ChatAnthropic"},{"note":"AnthropicLLM is a legacy class for text completion models (e.g., older Claude 2 models) and is generally deprecated in favor of ChatAnthropic. Older LangChain versions used 'from langchain.llms import Anthropic'.","wrong":"from langchain.llms import Anthropic","symbol":"AnthropicLLM","correct":"from langchain_anthropic import AnthropicLLM"}],"quickstart":{"code":"import os\nfrom langchain_anthropic import ChatAnthropic\nfrom langchain_core.messages import HumanMessage, SystemMessage\n\n# Set your Anthropic API key as an environment variable\n# os.environ[\"ANTHROPIC_API_KEY\"] = \"YOUR_ANTHROPIC_API_KEY\"\n\n# Ensure the API key is set\nif not os.environ.get(\"ANTHROPIC_API_KEY\"):\n    raise ValueError(\"ANTHROPIC_API_KEY environment variable not set.\")\n\nmodel = ChatAnthropic(model=\"claude-3-sonnet-20240229\", temperature=0)\n\nmessages = [\n    SystemMessage(content=\"You are a helpful AI assistant.\"),\n    HumanMessage(content=\"What is the capital of France?\"),\n]\n\nresponse = model.invoke(messages)\nprint(response.content)","lang":"python","description":"This quickstart demonstrates how to instantiate and use the `ChatAnthropic` model to get a response from a Claude chat model. It highlights the importance of setting the `ANTHROPIC_API_KEY` environment variable."},"warnings":[{"fix":"Migrate from `AnthropicLLM` to `ChatAnthropic` and adapt your code to use message-based input/output rather than string-in/string-out.","message":"The `AnthropicLLM` class for text completion models is considered legacy. For modern Anthropic models like Claude 3, it's strongly recommended to use `ChatAnthropic` instead, which supports the chat-based API.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Explicitly set `max_tokens=1024` (or your desired value) when instantiating `ChatAnthropic` or `AnthropicLLM` if you need to maintain the old behavior.","message":"The default value for the `max_tokens` parameter in `langchain-anthropic` changed with LangChain v1. Previously, it defaulted to 1024. Now, it defaults to higher values based on the specific model's `max_output_tokens` profile. If your application relied on the old default, it might now consume more tokens or exhibit different truncation behavior.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure `os.environ[\"ANTHROPIC_API_KEY\"]` is set to your valid Anthropic API key before initializing any Anthropic model classes. Consider using a `.env` file and `python-dotenv` for local development.","message":"It is crucial to set the `ANTHROPIC_API_KEY` environment variable for authentication. Without it, your application will fail when trying to connect to Anthropic models.","severity":"gotcha","affected_versions":"All"},{"fix":"Refer to the official LangChain v1 migration guides and update your imports and component usage according to the new patterns, focusing on partner packages like `langchain-anthropic` for model integrations.","message":"LangChain v1 introduced significant architectural changes, including a simplified `langchain` package namespace, revised import paths, and new patterns for agents and tools. Code written for `langchain==0.x` might require substantial modifications.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Only use tools like 'web fetch' in trusted environments or when handling non-sensitive data. Implement strict input validation and access controls.","message":"When using built-in Anthropic tools like the 'web fetch' tool, be aware of security implications. Enabling web fetching in environments where Claude processes untrusted input alongside sensitive data can pose data exfiltration risks.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-05T00:00:00.000Z","next_check":"2026-07-04T00:00:00.000Z"}