Docs

Email verification tool with the OpenAI API

Pass a function tool, run verify_email when the model returns a tool call, and reply with a tool message. SDK signatures change, so confirm them in OpenAI’s current documentation.

Tool definition

tools = [{
    'type': 'function',
    'function': {
        'name': 'verify_email',
        'description': 'Check whether one email address can receive mail. status unknown means no conclusion, not invalid.',
        'parameters': {
            'type': 'object',
            'properties': {'email': {'type': 'string'}},
            'required': ['email'],
        },
    },
}]

Run the tool

import json

for call in message.tool_calls or []:
    if call.function.name == 'verify_email':
        args = json.loads(call.function.arguments)
        out = verify_email(args['email'])  # see the AI tool pattern page
        messages.append({
            'role': 'tool',
            'tool_call_id': call.id,
            'content': json.dumps(out),
        })
# call the API again with the extended messages

Notes

Use a model name from OpenAI’s current list in your own configuration. Keep VALIDREACH_API_KEY on the server and cap tool calls per run.