{"slug": "add-email-verification-to-your-langchain-agent", "title": "Add email verification to your LangChain agent", "summary": "A developer integrated Verifly's email verification API into a LangChain agent to prevent the agent from sending emails to invalid addresses. The tool checks deliverability mid-loop, allowing the agent to skip bad addresses and suggest corrections, improving sending reputation and reducing bounces.", "body_md": "If your LangChain agent sends email, books demos, or accepts signups, sooner or later it will act on an address that does not exist. A typo like `gmial.com`\n\n, a disposable `mailinator.com`\n\nthrowaway, a dead domain. The agent has no way to know, so it sends anyway. The message bounces, your sending reputation drops, and the agent happily moves on to the next bad row.\n\nThe fix is to give the agent a tool that checks an address *before* it acts on it. This walkthrough wires [Verifly](https://verifly.email) into a LangChain agent so the model can verify deliverability mid-loop, the same way it would call any other tool.\n\nYou hand an agent a list of leads scraped from a CSV and ask it to draft outreach. Some of those addresses are garbage. You want the agent to skip the bad ones and flag the fixable ones, on its own, without you writing bounce-handling glue. That decision needs a real deliverability signal, and that is exactly what a verification tool provides.\n\n```\npip install langchain-verifly langchain langchain-openai\n```\n\nThe `langchain-verifly`\n\npackage ships a ready-made `BaseTool`\n\ncalled `VeriflyEmailVerifier`\n\n. You do not have to write a wrapper.\n\nVerifly is agent-native, so a key is one HTTP call away. No dashboard click-through required:\n\n```\ncurl -s -X POST https://verifly.email/api/v1/autonomous/register \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"email\":\"you@example.com\",\"password\":\"a-strong-password\"}'\n```\n\nThe response contains an `api_key.key`\n\n(it starts with `vf_`\n\n) and 100 free credits. Export it:\n\n```\nexport VERIFLY_API_KEY=\"vf_...\"\n```\n\nBefore handing it to an agent, run the tool directly so you can see the shape of what it returns. The class reads `VERIFLY_API_KEY`\n\nfrom the environment automatically:\n\n``` python\nfrom langchain_verifly import VeriflyEmailVerifier\n\nverifier = VeriflyEmailVerifier()  # picks up VERIFLY_API_KEY\n\nprint(verifier.run(\"jane.doe@gmial.com\"))\n```\n\nThat call against the live API returns:\n\n```\n{\n    'email': 'jane.doe@gmial.com',\n    'result': 'undeliverable',\n    'reason': 'Invalid email: bad_domain',\n    'confidence': 90,\n    'is_valid': False,\n    'recommendation': 'do_not_send',\n    'did_you_mean': 'jane.doe@gmail.com',\n    'details': {\n        'syntax_valid': True, 'domain_exists': True, 'mx_records': True,\n        'smtp_valid': False, 'is_disposable': False, 'is_role_account': False,\n        'is_catch_all': False, 'is_free_provider': False, 'provider': 'gmial.com'\n    }\n}\n```\n\nTwo things matter for an agent here. `recommendation`\n\nis a flat instruction (`do_not_send`\n\n), and `did_you_mean`\n\nproposes the correction `jane.doe@gmail.com`\n\n. The model can act on both without parsing anything fancy.\n\nA real address looks different:\n\n```\nprint(verifier.run(\"james@sibscientific.com\"))\n{\n    'email': 'james@sibscientific.com',\n    'result': 'deliverable',\n    'reason': 'Email exists and accepts mail',\n    'confidence': 95,\n    'is_valid': True,\n    'recommendation': 'safe_to_send',\n    'did_you_mean': None,\n    'details': {'smtp_valid': True, 'is_disposable': False, 'is_catch_all': False, ...}\n}\n```\n\nNow give the tool to an agent and let the model decide when to call it. The tool's own description (\"Use before emailing a lead or accepting a signup to avoid bounces\") is enough for the model to reach for it.\n\n``` python\nfrom langchain_openai import ChatOpenAI\nfrom langchain.agents import create_tool_calling_agent, AgentExecutor\nfrom langchain_core.prompts import ChatPromptTemplate\nfrom langchain_verifly import VeriflyEmailVerifier\n\ntools = [VeriflyEmailVerifier()]\n\nprompt = ChatPromptTemplate.from_messages([\n    (\"system\",\n     \"You clean lead lists. For each address, verify it. \"\n     \"Drop anything with recommendation 'do_not_send'. \"\n     \"If did_you_mean is set, suggest the corrected address instead.\"),\n    (\"human\", \"{input}\"),\n    (\"placeholder\", \"{agent_scratchpad}\"),\n])\n\nllm = ChatOpenAI(model=\"gpt-4o-mini\", temperature=0)\nagent = create_tool_calling_agent(llm, tools, prompt)\nexecutor = AgentExecutor(agent=agent, tools=tools, verbose=True)\n\nexecutor.invoke({\"input\":\n    \"Clean these: jane.doe@gmial.com, james@sibscientific.com, test@mailinator.com\"})\n```\n\nThe agent verifies each address and reasons over the structured verdict. The typo gets the `gmail.com`\n\ncorrection surfaced, the real address passes, and the throwaway is dropped because Verifly flags it:\n\n```\nverifier.run(\"test@mailinator.com\")\n# {'result': 'undeliverable', 'reason': 'Disposable/temporary email address',\n#  'recommendation': 'do_not_send', 'details': {'is_disposable': True, ...}}\n```\n\nSyntax checks catch `bad@@example`\n\n. They do not catch `gmial.com`\n\n, dead domains, disposable providers, or full mailboxes, because those require DNS, MX, and SMTP probing at request time. That is the work the tool does, and it returns one field, `recommendation`\n\n, that the model can branch on directly.\n\n`deliverable`\n\n, `undeliverable`\n\n, `risky`\n\n, or `unknown`\n\n. Treat `risky`\n\n(catch-all domains, confidence around 40) as \"send with caution,\" not \"drop.\"`risky`\n\nverdict there is honest, not a failure.That is the whole integration: one `pip install`\n\n, one tool in the `tools`\n\nlist, and your agent stops sending into the void. Docs and the rest of the API live at [verifly.email](https://verifly.email).", "url": "https://wpnews.pro/news/add-email-verification-to-your-langchain-agent", "canonical_source": "https://dev.to/jamessib/add-email-verification-to-your-langchain-agent-3e59", "published_at": "2026-06-28 08:44:34+00:00", "updated_at": "2026-06-28 09:03:47.422641+00:00", "lang": "en", "topics": ["developer-tools", "large-language-models", "ai-agents"], "entities": ["LangChain", "Verifly", "OpenAI", "GPT-4o-mini"], "alternates": {"html": "https://wpnews.pro/news/add-email-verification-to-your-langchain-agent", "markdown": "https://wpnews.pro/news/add-email-verification-to-your-langchain-agent.md", "text": "https://wpnews.pro/news/add-email-verification-to-your-langchain-agent.txt", "jsonld": "https://wpnews.pro/news/add-email-verification-to-your-langchain-agent.jsonld"}}