Module 3 Lesson 5: Prompt Versioning and the Hub
·LangChain

Module 3 Lesson 5: Prompt Versioning and the Hub

Prompts as Code. How to version-control your instructions and use the LangChain Hub to share and pull best-in-class prompts.

Prompt Versioning: Managing Change

In a professional agent project, you will change your prompts dozens of times. If you don't version them, you will lose track of which prompt version worked for which test case. We treat prompts like Artifacts.

1. Local Versioning (The "prompts/" folder)

The simplest way is to save each template version as a JSON file.

# Save version 1.0.0
prompt.save("prompts/customer_support_v1.json")

# Later, load it back
from langchain.prompts import load_prompt
old_prompt = load_prompt("prompts/customer_support_v1.json")

2. Introducing LangChain Hub

The LangChain Hub is like GitHub, but for prompts. It allows you to "Pull" high-quality, pre-tested prompts created by the community.

from langchain import hub

# Pull a standard RAG prompt
prompt = hub.pull("rlm/rag-prompt")

3. Creating Your Own Hub

Companies often host a Private Prompt Hub.

  • Advantage: The engineering team can update the prompt in the Hub UI, and every running agent in the cloud will get the update instantly without a code redeploy.

4. Visualizing the Deployment Cycle

graph TD
    Write[Write Prompt in Hub UI] --> Test[Run Benchmarks]
    Test -->|Pass| Tags[Tag as 'production']
    Tags --> Agent[Agent fetches 'production' tag]
    Agent --> User[Live Response]

5. Engineering Tip: Prompt metadata

When you save a prompt, always include metadata:

  • Who wrote it?
  • What model was it tested with? (A prompt for GPT-4 often fails on Llama-3).
  • What is the intended Temperature?

Key Takeaways

  • Version control prompts just like you version control code.
  • The LangChain Hub is a massive repository of best-in-class instructions.
  • Hub UI decoupling allows for prompt updates without script redeploys.
  • Always associate a prompt with a Specific Model in your metadata.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn