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.
Push a StructuredPrompt
AStructuredPrompt combines a prompt template with an output schema, ensuring the model returns data in a defined structure. Use StructuredPrompt.from_messages_and_schema (Python) or StructuredPrompt.fromMessagesAndSchema (TypeScript) to create one, then push it to the hub like any other prompt.
Without a model
Push the structured prompt on its own when you want to store the template and schema independently of any model configuration.With a model
Push the structured prompt as a RunnableSequence with a model to store the full pipeline, including model configuration, in the hub.Pull a prompt
To pull a prompt, you can use thepull prompt method, which returns 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
The LangSmith SDK includes built-in in-memory caching for prompts. When enabled, LangSmith will cache pulled prompts in memory, reducing latency and API calls for frequently used prompts. The cache uses a global singleton instance that is shared across all clients and persists for the lifetime of the process. It implements a stale-while-revalidate pattern, ensuring your application always gets a fast response while keeping prompts up-to-date in the background. Requirements:- Python SDK:
langsmith >= 0.7.0 - TypeScript SDK:
langsmith >= 0.5.0
Default behavior
Caching is enabled by default. When enabled, the default settings are:
When refreshing, the global cache will use the last client that requested a given prompt to fetch new data.
Using the cache
By default, all clients use the global prompt cache. No configuration is needed:Configuring the global cache
You can configure the global prompt cache that all clients use by default. This is useful when you want to customize caching behavior across your entire application:Disabling the cache
To disable caching for a specific client, passdisable_prompt_cache=True. You can also configure a max size of zero globally:
Skipping the cache
To bypass the cache and fetch a fresh prompt from the API for an individual request, 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 and disable background refresh.
Step 1: Export your prompts to a cache file (while online)
Cache operations
The cache supports several operations for managing cached prompts:Cleanup
You can manually callstop() to stop the background refresh task:
The background refresh task is only started when you first set a value in the cache, and only if
ttl_seconds is not None. If ttl_seconds is None (offline mode), no background task is created.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.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

