Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Learn/LangChain Mastery/Part 3 · 2. LCEL & Prompt Architecture
Lesson 16 of 68

Prompt Architecture & Reusability

Moving from magic strings to a Prompt Registry. How to manage large prompts.

Derpx0610 Jan · 1 min read
LangChain Mastery
Your First Chatbot: Talking to an LLMLCEL: Why LangChain Is a Composition EngineThe Runnable Protocol (invoke, batch, stream)Pipe Operator & Data FlowRunnableLambda & Custom LogicRunnableParallel & BranchingPromptTemplate vs ChatPromptTemplateSystem, Human, AI MessagesPrompt Architecture & ReusabilityStructured Output with JSON ModePydanticOutputParserOutputFixingParserStreaming Tokens & Async Chains
Contents
1. The "Magic String" Problem2. Solution: The Prompt Registry Pattern3. Composition (Layered Prompts)4. Summary
0% read · 1 min leftBack to top ↑
Course outline & contents0%
LangChain Mastery
Your First Chatbot: Talking to an LLMLCEL: Why LangChain Is a Composition EngineThe Runnable Protocol (invoke, batch, stream)Pipe Operator & Data FlowRunnableLambda & Custom LogicRunnableParallel & BranchingPromptTemplate vs ChatPromptTemplateSystem, Human, AI MessagesPrompt Architecture & ReusabilityStructured Output with JSON ModePydanticOutputParserOutputFixingParserStreaming Tokens & Async Chains
Contents
1. The "Magic String" Problem2. Solution: The Prompt Registry Pattern3. Composition (Layered Prompts)4. Summary

1. The "Magic String" Problem

In a demo, your prompt is 3 lines. In production, your prompt is 3 pages.

If you keep 3-page strings inside your Python files (main.py), your code becomes unreadable. You can't version control the logic separately from the text.

2. Solution: The Prompt Registry Pattern

Treat prompts like assets. Create a folder structure:

Text
src/
  prompts/
    __init__.py
    support_agent.py
    sales_agent.py

Inside support_agent.py:

support_agent.py
from langchain_core.prompts import ChatPromptTemplate

SYSTEM_TEMPLATE = """
You are a support agent for company X.
Current Time: {time}
Rules:
1. Be polite.
2. Never promise refunds.
"""

def get_support_prompt():
  return ChatPromptTemplate.from_messages([
      ("system", SYSTEM_TEMPLATE),
      ("human", "{input}")
  ])

This seems simple, but it allows you to:

  1. Import the prompt anywhere: from prompts.support_agent import get_support_prompt
  2. Test the prompt in isolation.
  3. Diff changes easily in Git (text files).

3. Composition (Layered Prompts)

Sometimes you have a "Base Prompt" (Company Tone) and a "Specific Prompt" (Task). You can compose them.

composition.py
BASE_SYSTEM = "Always speak in a professional tone."

TASK_SPECIFIC = "User is asking about billing."

full_prompt = ChatPromptTemplate.from_messages([
  ("system", BASE_SYSTEM),
  ("system", TASK_SPECIFIC), # Yes, you can stack system messages
  ("human", "{input}")
])

4. Summary

Don't bury prompts in your logic. Externalize them. Modularize them.

Key Intuition: "Prompts should evolve like code."

Track your progressSign in and your progress follows you across devices.
Sign in to track progress Next lesson
← Previous lessonSystem, Human, AI MessagesNext lesson →Structured Output with JSON Mode