16 of 174 subtitles documented + 1 independent supplementary unit(s) · Writing progress, not your learning progress · Videos not visually reviewed
What should you be able to explain?
Trace an input from a dictionary through a template and model to a response message. Explain what | constructs, when invoke executes the work, and how an input-name failure differs from a poor model response. Prerequisites: the project environment lesson, Python dictionaries, and function calls.
Entry check: where does a value go in "Hello, {name}"? Which function produces its result first in f(g(x))? Is constructing an object the same as executing it? If you cannot explain these with examples, repair these Python concepts first.
Why use templates and chains?
Lecture 009 introduces one instruction reused for different products. Lecture 010 applies the same idea to information about a person. The fixed part says to summarize; the variable part contains that person's information.
String formatting and function composition are longstanding programming ideas, not LangChain inventions. The framework adds a common execution contract for connecting different components. This limited historical framing also prevents the misconception that every simple model request requires a framework.
Start with plain Python
template = "Summarize: {information}"
text = template.format(information="Mina teaches Python.")
The result is only a formatted string; no model has run. An f-string or format can suffice for a simple task. PromptTemplate becomes useful when the template should participate as a reusable component in a LangChain workflow.
A complete example without keys or network calls
This original teaching example sends fixed input to a test model. Its executable file is first_chain.py; behavioral checks are in check_chain.py.
from langchain_core.prompts import PromptTemplate
from langchain_core.language_models.fake_chat_models import FakeListChatModel
prompt = PromptTemplate.from_template(
"Summarize only the supplied information in one sentence.\n"
"Information: {information}"
)
model = FakeListChatModel(
responses=["Mina teaches Python and built a robot in 2024."]
)
chain = prompt | model
result = chain.invoke({
"information": "Mina teaches Python. She built a robot in 2024."
})
print(result.content)
The preset output is:
Mina teaches Python and built a robot in 2024.
FakeListChatModel does not understand or summarize the text. It returns a reply from a list. Changing the input can still produce the same reply. This limitation helps separate correct component wiring from the intelligence and output quality of a real model.
Follow the actual types
chain.invokereceives a dictionary containinginformation.- The template inserts its value at
{information}, producing aStringPromptValue. - The chat model receives that input and returns an
AIMessage. - In this example,
result.contentis the reply string. Message content can have other structures in general; a message is not always interchangeable with raw text.
PromptValue is not merely a fancy name for a string. It is an object that can supply a suitable representation, such as text or messages. This corrects a simplification in the subtitles.
Text templates versus message templates
Our PromptTemplate produces formatted text. Its StringPromptValue message representation is a human message when passed to the chat model. Prefixing that text with System: ... does not automatically create a system-role message.
When fixed instructions, history, and the question need separate roles, use ChatPromptTemplate. It produces a ChatPromptValue whose role-bearing messages can be inspected with to_messages(). These are different input structures for different needs, not contradictory mechanisms. context_lab.py checks both without running a model.
See context and memory foundations for why history needs application management. This is more than a class-name distinction: identify exactly which instructions and data reached the call and with what roles.
What does prompt | model do?
Here LangChain defines | to compose runnables. The resulting object is a RunnableSequence. Constructing it does not itself call the model. Invoking it runs the template first and passes its output to the model. This notation is part of LCEL, the LangChain Expression Language. Runnable reference
For the data-flow intuition, imagine:
prompt_value = prompt.invoke({"information": information})
result = model.invoke(prompt_value)
These lines illustrate ordering. They do not claim to reproduce every composition, configuration, or tracing capability of RunnableSequence. Also, | does not mean chaining everywhere in Python; its behavior depends on operand types.
Deliberate failure: the wrong input key
chain.invoke({"info": "Mina teaches Python."})
The template expects information, not info. In the verified example, this failure happens before the model stage. Calling it a bad model answer would misdiagnose it. First inspect each stage's input contract.
Corrections to the subtitle explanation
- Templates and security: PromptTemplate manages variables and formatting; it is not a security boundary against prompt injection. Template type matters too: the official reference cautions against untrusted Jinja2 templates. PromptTemplate reference
- Temperature and truth: the subtitles associate low temperature with definite, factual answers. Sampling controls do not verify facts or guarantee complete reproducibility, and parameter support depends on the model. Our example does not set temperature.
- Chat model output: the result is a message object, not always raw text. Extract the representation appropriate to that message.
- Capabilities are explicit: this example does not automatically add history, retrieval, tools, or external tracing.
Live execution replaces the test model with a provider integration. The instructor demonstrates ChatOpenAI; its official integration guide describes model construction and response messages. No real or paid inference was performed at this stage.
Independent practice
- Predict before running: change
{information}to{profile}without changing the dictionary key. Where does execution fail? - With the original template, create a
PromptValuefor “Sara studies biology.” and inspectto_string(). Has a model run? - Change the test model's input. What does an unchanged answer establish about the test model, and what does it establish about the chain?
- Create a template requesting two questions about a text rather than a summary. Which behavior can you verify without a real model, and which behavior cannot you evaluate?
Answer 1
The template stage fails because profile is missing. The request does not reach the model. Template variables and input keys must agree.
Answer 2
prompt.invoke({"information": "Sara studies biology."}).to_string() reveals the instruction with the new text. Only the template has run, not the model.
Answer 3
The test model depends on a preset reply and does not analyze the changed meaning. An unchanged output alone does not establish that the new input reached it correctly. Capture and inspect the model-stage input to verify that, as check_chain.py does.
Answer 4
You can verify the final prompt, substitution, ordering, and output type. A predetermined reply cannot evaluate the quality, relevance, or correctness of generated questions.
Recall, error analysis, and continuation
Without the code, state every stage's input and output, why invoke is necessary, and why this is not an agent. If you can explain the flow and independently repair the key mismatch, continue to lecture 011 on debugging and tracing. If you have only memorized the code, retry exercises 2 and 4 with new text.
In private notes, record “symptom → cause → repair → retry result.” For example: KeyError → mismatched input name → align profile → rerun. These personal records are separate from public course content. In another session, retrieve the distinctions between a chain and an agent, and between a message and a string.
Provenance and validation
Course basis: lecture 009 subtitles through approximately 05:53 and lecture 010 through approximately 11:12. The fictional example, test model, type diagram, corrections, and exercises are supplementary. The example and failure-order checks ran with langchain-core==1.5.2. Sources checked on 2026-10-16; online reference material may describe a newer version. Videos have not been visually reviewed. Next lesson: debugging and message inspection, 011.