Challenge - 5 Problems
LangChain Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
What is the primary purpose of LangChain?
LangChain is a framework designed to help developers build applications that use large language models (LLMs). What is its main goal?
Attempts:
2 left
💡 Hint
Think about how LangChain helps combine language models with other parts of an app.
✗ Incorrect
LangChain focuses on making it easier to build apps that use language models by connecting them with data, APIs, and other tools.
❓ component_behavior
intermediate2:00remaining
How does LangChain handle external data sources?
In LangChain, which component is responsible for connecting language models to external data like documents or APIs?
Attempts:
2 left
💡 Hint
This component sequences calls and manages data flow.
✗ Incorrect
Chains in LangChain organize steps and connect language models to external data sources or APIs.
📝 Syntax
advanced3:00remaining
What is the correct way to create a simple LangChain chain with an LLM?
Given the following code snippets, which one correctly creates a chain that uses an OpenAI LLM to generate text?
LangChain
from langchain.llms import OpenAI from langchain.chains import LLMChain from langchain.prompts import PromptTemplate prompt = PromptTemplate(template="Say hello to {name}.", input_variables=["name"]) llm = OpenAI() chain = ???
Attempts:
2 left
💡 Hint
Check the required parameters for LLMChain constructor.
✗ Incorrect
LLMChain requires both the llm and prompt parameters to be passed explicitly.
❓ state_output
advanced3:00remaining
What output does this LangChain code produce?
Consider this LangChain code snippet that uses a prompt template and an OpenAI LLM to greet a user named 'Alice'. What is the expected output?
LangChain
from langchain.llms import OpenAI from langchain.chains import LLMChain from langchain.prompts import PromptTemplate prompt = PromptTemplate(template="Say hello to {name}.", input_variables=["name"]) llm = OpenAI(temperature=0) chain = LLMChain(llm=llm, prompt=prompt) result = chain.run(name="Alice") print(result)
Attempts:
2 left
💡 Hint
The LLM generates a polite greeting based on the prompt.
✗ Incorrect
With temperature 0, the model produces a deterministic polite greeting including a comma and exclamation mark.
🔧 Debug
expert4:00remaining
Why does this LangChain agent code raise an error?
This code tries to create an agent with tools but raises a TypeError. What is the cause?
LangChain
from langchain.agents import initialize_agent, Tool from langchain.llms import OpenAI llm = OpenAI() tools = [Tool(name="Search", func=lambda x: "Found: " + x, description="Search tool")] agent = initialize_agent(tools, llm) result = agent.run("Find cats")
Attempts:
2 left
💡 Hint
Check the parameters required by initialize_agent function.
✗ Incorrect
initialize_agent needs the agent type (like 'zero-shot-react-description') as a third argument to know how to run.