Docs
Email verification tool with LangChain
Define the tool with the tool function from @langchain/core/tools, a name, a description and a Zod schema. The example matches the LangChain documentation as of October 2026; confirm the current signatures in the LangChain docs, because package layout changes between versions.
Tool definition
import { tool } from '@langchain/core/tools';
import { z } from 'zod';
export const verifyEmail = tool(
async ({ email }) => {
const res = await fetch('https://validreach.dev/api/v1/verify/single', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.VALIDREACH_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ email }),
});
const body = await res.json();
if (!body.success) return JSON.stringify({ error: body.message });
const { status, is_deliverable, reason, retryable } = body.data;
return JSON.stringify({ email, status, is_deliverable, reason, retryable });
},
{
name: 'verify_email',
description:
'Check whether one email address can receive mail. status unknown means no conclusion, not invalid.',
schema: z.object({ email: z.string() }),
}
);
// Pass `verifyEmail` in the tools list of your agent or bind it to a chat model.Notes
Attach the tool to the agent or chat model you use, following the LangChain documentation for your version.
Keep VALIDREACH_API_KEY on the server and cap how many tool calls a run may make, because each definite result spends a credit. For decisions that matter, branch on data.status in your own code rather than on the model’s summary.
Related