This is a TypeScript project that demonstrates how to pull prompts from LangSmith using the LangChain library with the langchain/hub/node entrypoint.
- Node.js (v16 or higher)
- npm or yarn
- LangSmith API key
-
Install dependencies:
npm install
-
Set up your LangSmith API key as an environment variable:
export LANGSMITH_API_KEY=your_api_key_here(Create an API key in LangSmith Settings > API Keys)
To pull a prompt from LangSmith:
-
Set the prompt identifier in an environment variable:
export LANGSMITH_PROMPT_ID=your-prompt-name -
Run the project:
npm run dev
# Pull the latest version of a prompt
export LANGSMITH_PROMPT_ID=my-chat-prompt
npm run dev
# Pull a specific commit version of a prompt
export LANGSMITH_PROMPT_ID=my-chat-prompt:abc12345
npm run devThe script uses langchain/hub/node to:
- Pull prompts from your LangSmith workspace
- Attempt to deserialize models included in the prompt (with fallback)
- Display the prompt structure as JSON
- Run validation checks on the pulled prompt (version extraction, prompt info)
- Uses
langchain/hub/nodeentrypoint for Node.js - Automatically handles API authentication via
LANGSMITH_API_KEY - Graceful fallback when prompt includes serialized models that can't be deserialized
- Clear error messages with debugging information
- JSON output of retrieved prompts
- Validation checks including prompt version extraction and metadata inspection
- Single consolidated module (
checks.ts) for all prompt validation logic
src/index.ts- Main entry point that pulls prompts from LangSmithsrc/checks.ts- Prompt validation and version extraction logictsconfig.json- TypeScript configuration with Node16 module resolutionpackage.json- Dependencies and scriptsdist/- Compiled JavaScript output
For development with automatic TypeScript compilation:
npm run devnpm run buildThis will compile the TypeScript code to JavaScript in the dist directory.
Then run:
node dist/index.jsFor more information about pulling prompts from LangSmith, visit: https://docs.langchain.com/langsmith/manage-prompts-programmatically