Skip to main content
In this guide, we’ll walk through creating a custom LangChain tool that retrieves flight status details. You’ll learn how to define the tool, inspect its metadata, and wire it into a prompt–LLM chain for concise, one-word or short answers.

Defining the Tool

First, install or import the required packages:
Then define your tool using the @tool decorator from LangChain:
The @tool decorator registers the function’s name, description, and argument schema automatically.

Inspecting Tool Metadata

After defining GetFlightStatus, you can verify its registered metadata:
You can also view the complete StructuredTool representation:
For a quick overview, here’s how the metadata maps out:

Using the Tool in a Chain

Next, we’ll connect the tool to a prompt template, the OpenAI LLM, and a simple output parser:
Run the tool to generate the context:
Compose the chain by piping the prompt into the LLM and then into the parser:

Invoking the Chain

With the chain ready, invoke it to extract specific details:
Each invocation returns a concise answer tailored by your prompt design.
You now have a reusable flight status tool. Integrate real-world APIs inside GetFlightStatus to fetch live data, and combine multiple tools to build sophisticated LangChain agents.

Watch Video

Practice Lab