ContiAI-v3 / tools /validate_url.py
ziadsameh32's picture
scraper
200825a
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)