langchain/hub module allows you to pull prompts from the hub and optionally push your own prompts.
Core Functions
pull
Pulls a prompt from the LangChain Hub.The hub identifier in the format
owner/repo or owner/repo/commit. Examples:"hwchase17/react-json"- Latest version"hwchase17/react-json/abc123"- Specific commit
LangSmith API key. If not provided, uses the
LANGSMITH_API_KEY environment variable.LangSmith API URL. Defaults to
https://api.smith.langchain.com.Whether to instantiate and attach a model instance to the prompt if the prompt has associated model metadata.When
true, invoking the pulled prompt will also invoke the model. For non-OpenAI models, you must also set modelClass.The class constructor for non-OpenAI models when Not needed in Node.js when using
includeModel is true.langchain/hub/node entrypoint.A map of secrets to use when loading the prompt, e.g.,
{ 'OPENAI_API_KEY': 'sk-...' }.If a secret is not found in the map, it will be loaded from the environment if secretsFromEnv is true.Whether to load secrets from environment variables. Use with caution and only with trusted prompts.
LangSmith client instance to use. If not provided, a new client is created.
Whether to skip the global default cache when pulling the prompt.
Promise<Runnable> - A runnable prompt that can be invoked.
Source: libs/langchain/src/hub/index.ts:40
push
Pushes a prompt to the LangChain Hub.The hub identifier in the format
owner/repo where the prompt will be stored.The prompt to push to the hub.
LangSmith API key. If not provided, uses the
LANGSMITH_API_KEY environment variable.LangSmith API URL. Defaults to
https://api.smith.langchain.com.LangSmith client instance to use.
Promise<void>
Source: Re-exported from libs/langchain/src/hub/base.ts
Examples
Basic Prompt Pull
Pull Specific Commit
Pull with Model (OpenAI)
Pull with Model (Other Providers)
Push a Prompt
Using Custom LangSmith Client
Loading with Environment Secrets
Skip Cache
Node.js Entrypoint
For Node.js environments with dynamic import support, use thelangchain/hub/node entrypoint:
libs/langchain/src/hub/node.ts
Environment Variables
The hub module respects the following environment variables:LANGSMITH_API_KEY- Your LangSmith API key for authenticationLANGSMITH_API_URL- Custom LangSmith API URL (optional)
Prompt Format
Prompts pulled from the hub are typically one of:ChatPromptTemplate- For chat-based interactionsPromptTemplate- For single-string promptsMessagesPlaceholder- For flexible message insertion
Runnable instances that can be:
- Invoked:
await prompt.invoke({ input: "..." }) - Streamed:
await prompt.stream({ input: "..." }) - Batched:
await prompt.batch([{ input: "..." }]) - Piped:
prompt.pipe(model).pipe(parser)
Error Handling
Security Considerations
Related
- LangSmith Hub - Browse and share prompts
- Prompts - Creating and working with prompts
- LangSmith Documentation - LangSmith platform docs
