Questions
17 of 24
1What is a Tool in LangChain and how does it differ from a plain function or API call?
2What is the difference between the tool() helper, DynamicTool, and StructuredTool class?
3How does an LLM decide which tool to call — what role does the tool description play?
4What is the role of Zod schema in tool definitions and how does it map to OpenAI's function calling spec?
5What is a ToolNode in LangGraph and how does it differ from calling a tool manually inside a graph node?
6How do you wrap a REST API call with auth headers inside a Tool in TypeScript?
7How do you handle async errors and retries inside a Tool without crashing the agent loop?
8How do you pass runtime context (userId, authToken, DB connection) into a Tool using RunnableConfig?
9How do you build a Toolkit (grouped set of related tools) using BaseToolkit?
10How do you validate and sanitize tool output before it is passed back to the LLM?
11How do you stream tool call results back to the client in real time?
12How do you implement tool-level authorization — allowing certain tools only for certain users?
13How do you build stateful tools that read/write to a database across multiple agent turns?
14How do you prevent tool abuse or infinite loops where an agent keeps calling the same tool repeatedly?
15How do you implement parallel tool calling — when the LLM decides to call multiple tools simultaneously?
16How do you create a human-in-the-loop tool that pauses the agent and waits for user approval before executing?
17How do you unit test and mock tools in isolation without invoking the LLM?
18How do you implement tool call caching to avoid redundant API calls for identical inputs?
19How do you design a multi-agent system where one agent's tool is actually another agent (agent-as-tool pattern)?
20How does LangGraph's ToolNode handle tool call errors and surface them back into the message state?
21What is the difference between tool_choice: "auto", "required", and "none" when binding tools to an LLM?
22How do you implement dynamic tool loading — where the set of available tools changes based on user role or session state?
23How do you trace and observe tool call latency in production using LangSmith?
24What are the token cost implications of registering too many tools and how do you mitigate it?
17 / 24

How do you unit test and mock tools in isolation without invoking the LLM?

Difficulty: 6/10
mocking LLM calls, langchain tool testing, unit testing isolation

Unit test tools in isolation by directly invoking them with test inputs, bypassing the LLM entirely. For testing tool integration with the agent, use langchain's @langchain/net-mocks to record and replay network responses, or mock the underlying API calls using standard mocking libraries.

Tools are plain functions and can be unit tested directly by calling their invoke method with test inputs, completely bypassing the LLM. For testing the full tool-calling flow (how the agent decides to call tools), langchain provides @langchain/net-mocks, which captures HTTP requests and responses during a test run and replays them in subsequent runs, making tests deterministic and offline-capable[citation:5].

Unit Testing Tools in Isolation

Scenario Questions

0-2 years experience

  1. 1Suppose you have a LangChain chain that calls an OpenAI LLM via the OpenAIChat model. How would you write a unit test that verifies the chain's logic without actually sending a request to the OpenAI API?
  2. 2If you need to mock a custom tool that fetches data from a REST endpoint inside a LangChain tool, what steps would you take to replace the real HTTP call in your test?
  3. 3What happens if you forget to reset the mock between test cases? How would that affect your test suite?

2-5 years experience

  1. 1You added a new LangChain tool that wraps a third‑party sentiment analysis service. During integration testing the chain hangs. Walk me through how you would debug the mock setup and why the real service might still be getting called.
  2. 2Explain the trade‑offs between using LangChain’s built‑in FakeLLM versus a library like unittest.mock to isolate LLM calls in a feature that streams partial responses.
  3. 3Your CI pipeline started failing because the mock for the LLM returns a different shape than the real API. How would you adjust your tests to catch such schema mismatches early?

5-8 years experience

  1. 1Design a testing strategy for a production LangChain application that composes multiple tools, some of which have side effects such as writing to a database. How would you ensure each component is unit‑tested in isolation while still being able to run end‑to‑end integration tests efficiently?
  2. 2At scale, mocking LLM calls can hide latency and token‑usage bugs. How would you augment your unit tests to also capture performance characteristics without invoking the real model?
  3. 3Your team wants to migrate from OpenAI’s GPT‑3.5 to a self‑hosted LLM. What changes would you make to the existing mock infrastructure to support both providers during the transition?

8+ years experience

  1. 1Across several product teams you notice inconsistent mocking approaches for LangChain tools, leading to flaky tests. Propose an organization‑wide framework or library that standardizes mocking LLMs and external tools, and discuss how you’d handle versioning and backward compatibility.
  2. 2When legacy LangChain pipelines are being refactored, how would you evaluate the risk of removing existing mocks and replacing them with contract tests? What metrics would you track to ensure reliability during the migration?
  3. 3Consider a multi‑region deployment where some LangChain tools call region‑specific services. How would you design a mock layer that can simulate regional failures and latency variations for unit and chaos testing?

Follow-up Questions

  • How would you verify that your mock correctly mimics the real LLM's response format?
  • What would you do if a new version of a LangChain tool changes its constructor signature?
  • Can you explain how you’d integrate these mocks into a CI pipeline to keep test times low?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.