Bird
Raised Fist0
LangChainframework~20 mins

LangChain architecture overview - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
LangChain Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Core components of LangChain architecture
Which of the following is NOT a core component of LangChain's architecture?
ADatabases that store user interface layouts
BChains that link multiple calls to language models
CAgents that decide which actions to take based on inputs
DMemory modules that keep track of conversation history
Attempts:
2 left
💡 Hint
Think about what LangChain focuses on: language models, decision making, and memory.
component_behavior
intermediate
2:00remaining
Behavior of memory in LangChain
What is the main role of the memory component in LangChain's architecture?
ATo visualize the output of language models in a dashboard
BTo execute external API calls during chain execution
CTo store and retrieve past interactions to provide context
DTo generate new language model prompts automatically
Attempts:
2 left
💡 Hint
Memory helps keep track of what happened before.
📝 Syntax
advanced
2:00remaining
Correct way to define a simple LangChain chain
Which code snippet correctly creates a simple chain that calls a language model with a prompt?
A
from langchain import LLMChain, OpenAI
chain = LLMChain(llm=OpenAI(), prompt="Hello")
B
from langchain import LLMChain, OpenAI, PromptTemplate
chain = LLMChain(llm=OpenAI(), prompt=PromptTemplate(template="Hello"))
C
from langchain import Chain, OpenAI
chain = Chain(llm=OpenAI(), prompt="Hello")
D
from langchain import LLMChain
chain = LLMChain(llm=OpenAI, prompt="Hello")
Attempts:
2 left
💡 Hint
Prompt must be a PromptTemplate object, not a plain string.
lifecycle
advanced
2:00remaining
Agent decision-making process in LangChain
During execution, how does a LangChain agent decide which action to take next?
AIt uses the language model output to interpret the input and select an action
BIt randomly selects an action from a predefined list
CIt always executes all actions in sequence regardless of input
DIt waits for user input before deciding any action
Attempts:
2 left
💡 Hint
Agents use language models to understand and decide.
🔧 Debug
expert
2:00remaining
Identifying error in LangChain memory usage
What error will this code raise? from langchain.memory import ConversationBufferMemory memory = ConversationBufferMemory() print(memory.load_memory_variables({}))
LangChain
from langchain.memory import ConversationBufferMemory
memory = ConversationBufferMemory()
print(memory.load_memory_variables({}))
AAttributeError: 'ConversationBufferMemory' object has no attribute 'load_memory_variables'
BTypeError: load_memory_variables() missing 1 required positional argument
CKeyError: 'history' not found in memory variables
DReturns an empty dictionary {} without error
Attempts:
2 left
💡 Hint
Check the method signature and default behavior of load_memory_variables.

Practice

(1/5)
1. What is the main purpose of a chain in LangChain architecture?
easy
A. To link different steps like prompts and LLMs to build language apps
B. To store data permanently in a database
C. To create user interfaces for language models
D. To train new language models from scratch

Solution

  1. Step 1: Understand the role of chains

    Chains connect parts like prompt templates and language models to form a workflow.
  2. Step 2: Identify the main purpose

    Chains help organize and link these steps to build smart language apps easily.
  3. Final Answer:

    To link different steps like prompts and LLMs to build language apps -> Option A
  4. Quick Check:

    Chains link steps = D [OK]
Hint: Chains connect prompts and models to build apps [OK]
Common Mistakes:
  • Thinking chains store data permanently
  • Confusing chains with UI components
  • Assuming chains train models
2. Which of the following is the correct way to create a prompt template in LangChain?
easy
A. PromptTemplate.create("Hello, {name}!")
B. PromptTemplate("Hello, {name}!")
C. PromptTemplate(template="Hello, {name}!")
D. PromptTemplate.new(template="Hello, {name}!")

Solution

  1. Step 1: Recall PromptTemplate syntax

    PromptTemplate requires a named argument 'template' with the string pattern.
  2. Step 2: Match syntax to options

    Only PromptTemplate(template="Hello, {name}!") uses PromptTemplate(template="...") correctly.
  3. Final Answer:

    PromptTemplate(template="Hello, {name}!") -> Option C
  4. Quick Check:

    Named 'template' argument = A [OK]
Hint: Use named 'template' argument to create PromptTemplate [OK]
Common Mistakes:
  • Passing template string without argument name
  • Using non-existent create() or new() methods
  • Confusing positional and keyword arguments
3. Given this code snippet, what will be the output?
from langchain import PromptTemplate, LLMChain

prompt = PromptTemplate(template="What is the capital of {country}?")
chain = LLMChain(prompt=prompt)
result = chain.run(country="France")
print(result)
medium
A. "Paris"
B. An error because LLM is missing
C. "What is the capital of France?"
D. "France"

Solution

  1. Step 1: Analyze the code components

    The chain is created with a prompt but no LLM (language model) is provided.
  2. Step 2: Understand LangChain requirements

    LLMChain needs an LLM to generate answers; missing it causes an error.
  3. Final Answer:

    An error because LLM is missing -> Option B
  4. Quick Check:

    LLM missing causes error = B [OK]
Hint: LLMChain needs an LLM instance to run [OK]
Common Mistakes:
  • Assuming chain.run returns prompt text
  • Expecting output without LLM
  • Confusing prompt template with output
4. Identify the error in this LangChain code snippet:
from langchain import PromptTemplate, LLMChain

prompt = PromptTemplate(template="Say hello to {name}")
chain = LLMChain(prompt=prompt, llm=None)
output = chain.run(name="Alice")
print(output)
medium
A. LLMChain requires a valid LLM, not None
B. PromptTemplate syntax is incorrect
C. run() method does not accept arguments
D. Missing import for LLM class

Solution

  1. Step 1: Check PromptTemplate usage

    PromptTemplate is correctly created with a template string.
  2. Step 2: Check LLMChain initialization

    LLMChain requires a valid LLM object; passing None causes failure.
  3. Final Answer:

    LLMChain requires a valid LLM, not None -> Option A
  4. Quick Check:

    LLM must be valid, not None = A [OK]
Hint: LLMChain needs a real LLM instance, not None [OK]
Common Mistakes:
  • Thinking run() can't take arguments
  • Assuming PromptTemplate syntax is wrong
  • Missing imports but not causing this error
5. You want to build a LangChain app that asks a user's name, then uses an LLM to greet them. Which architecture correctly links these parts?
hard
A. Create a PromptTemplate and run it directly without an LLMChain
B. Create an LLMChain without a prompt and run it with user input
C. Create an LLM instance and call it directly without prompt or chain
D. Create a PromptTemplate for the question, then an LLMChain with that prompt and an LLM, then run the chain with user input

Solution

  1. Step 1: Understand LangChain app structure

    PromptTemplate creates the question, LLMChain links prompt and LLM to generate answers.
  2. Step 2: Identify correct linking

    Create a PromptTemplate for the question, then an LLMChain with that prompt and an LLM, then run the chain with user input correctly creates prompt, then LLMChain with prompt and LLM, then runs with input.
  3. Final Answer:

    Create a PromptTemplate for the question, then an LLMChain with that prompt and an LLM, then run the chain with user input -> Option D
  4. Quick Check:

    Prompt + LLM in chain = C [OK]
Hint: Chain = prompt + LLM + run with input [OK]
Common Mistakes:
  • Trying to run prompt alone without chain
  • Using LLM without prompt or chain
  • Skipping linking steps in LangChain