Previously this functionality lived in the
langchainhub package which is now deprecated. All functionality going forward will live in the langsmith package.Install packages
In Python, you can directly use the LangSmith SDK (recommended, full functionality) or you can use through the LangChain package (limited to pushing and pulling prompts). In TypeScript, you must use the LangChain npm package for pulling prompts (it also allows pushing). For all other functionality, use the LangSmith package.Configure environment variables
If you already haveLANGSMITH_API_KEY set to your current workspace’s api key from LangSmith, you can skip this step.
Otherwise, get an API key for your workspace by navigating to Settings > API Keys > Create API Key in LangSmith.
Set your environment variable.
What we refer to as “prompts” used to be called “repos”, so any references to “repo” in the code are referring to a prompt.
Push a prompt
To create a new prompt or update an existing prompt, you can use thepush prompt method.
Pull a prompt
To pull a prompt, you can use thepull prompt method, which returns a the prompt as a langchain PromptTemplate.
To pull a private prompt you do not need to specify the owner handle (though you can, if you have one set).
To pull a public prompt from the LangChain Hub, you need to specify the handle of the prompt’s author.
For pulling prompts, if you are using Node.js or an environment that supports dynamic imports, we recommend using the
langchain/hub/node entrypoint, as it handles deserialization of models associated with your prompt configuration automatically.If you are in a non-Node environment, “includeModel” is not supported for non-OpenAI models and you should use the base langchain/hub entrypoint.Prompt caching
We recommend enabling prompt caching in production environments to reduce latency and API calls. The cache uses a stale-while-revalidate pattern, ensuring your application always gets a fast response while keeping prompts up-to-date in the background.
- Python SDK:
langsmith >= 0.6.1 - TypeScript SDK:
langsmith >= 0.4.5
Default behavior
Caching is disabled by default. When enabled, the default settings are:Enabling the cache
Passcache=True to enable caching with default settings, or pass a Cache instance for custom configuration:
Skipping the cache
To bypass the cache and fetch a fresh prompt from the API, use theskip_cache parameter:
Offline mode
For environments with limited or no network connectivity, you can pre-populate the cache and use it offline. Setttl_seconds to None (Python) or null (TypeScript) to prevent cache entries from expiring.
Step 1: Export your prompts to a cache file (while online)
Cleanup
When you’re done using the client, callcleanup() to stop the background refresh task:
Use a prompt without LangChain
If you want to store your prompts in LangSmith but use them directly with a model provider’s API, you can use our conversion methods. These convert your prompt into the payload required for the OpenAI or Anthropic API. These conversion methods rely on logic from within LangChain integration packages, and you will need to install the appropriate package as a dependency in addition to your official SDK of choice. Here are some examples:OpenAI
Anthropic
List, delete, and like prompts
You can also list, delete, and like/unlike prompts using thelist prompts, delete prompt, like prompt and unlike prompt methods. See the LangSmith SDK client for extensive documentation on these methods.