Personalized Prompts (Upload to LangChain Hub)

What it is Personalized prompts are your own custom PromptTemplate or FewShotPromptTemplate that you design for a specific task or workflow. Uploading them to LangChain Hub makes them shareable and reusable across projects or with others.

Why it exists Instead of rewriting the same prompts for every project, you can store them centrally and reuse them. Hub also allows collaboration, versioning, and quick access to tested prompts. It saves time and ensures consistency.

Real-world analogy Think of it like creating your own recipe card. You tweak a cake recipe to perfection and then share it in a community cookbook so others can use it exactly the same way.

Minimal beginner example

import os
from dotenv import load_dotenv
from langchain_core.prompts import PromptTemplate
from langchain_core.hub import HubWriter

load_dotenv()
api_key = os.getenv("GEMINI_API_KEY")

# Step 1: Create a personalized prompt
my_prompt = PromptTemplate(
    template="Summarize the following text in 2 sentences:\n{text}",
    input_variables=["text"]
)

# Step 2: Upload it to LangChain Hub
hub_writer = HubWriter(api_key=api_key)
hub_writer.upload_prompt(
    prompt=my_prompt,
    name="two_sentence_summary",
    description="Summarizes any text into two concise sentences."
)

print("Prompt uploaded successfully!")

Once uploaded, you or your team can load this prompt from Hub in any project.

Small LangChain workflow

  1. Design a custom prompt (PromptTemplate or FewShotPromptTemplate).

  2. Test it locally with your LLM.

  3. Upload it to Hub with HubWriter.

  4. Load it in other projects or share with teammates.

  5. Integrate it into chains or agents like any other prompt.

Common beginner mistakes

  • Forgetting to test the prompt locally before uploading.

  • Uploading without proper description—others won’t know its purpose.

  • Using private API keys in uploaded templates (keep keys local).

When to use this vs alternatives

  • Use personalized prompts + Hub if you want reuse, sharing, or standardization.

  • Use local prompts if it’s a one-time or private project.

  • Hub is not for storing large datasets or models—just prompts and chains.

Last updated