ContiAI / tools /validate_url.py
ziadsameh32's picture
Add login page
325b94c
Raw
History Blame Contribute Delete
917 Bytes
from crewai.tools import BaseTool
from typing import Literal
import requests
class URLValidatorTool(BaseTool):
name: Literal["url_validator"]
description : str = "Validate whether a given URL is reachable and returns a valid HTTP status."
def _run(self, url: str) -> dict:
"""Synchronous tool execution"""
try:
response = requests.head(url, allow_redirects=True, timeout=15)
return {
"url": url,
"status_code": response.status_code,
"ok": response.status_code < 400
}
except Exception as e:
return {
"url": url,
"status_code": None,
"ok": False,
"error": str(e)
}
async def _arun(self, url: str) -> dict:
"""Asynchronous tool execution (not used but required)"""
return self._run(url)