{"record":{"id":"20e92f47e25f9f82","repo":"crewAIInc/crewAI","slug":"invalid-youtube-url-video-url","errorCode":null,"errorMessage":"Invalid YouTube URL: {video_url}","messagePattern":"Invalid YouTube URL: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/rag/loaders/youtube_video_loader.py","lineNumber":39,"sourceCode":"            LoaderResult with transcript content\n\n        Raises:\n            ImportError: If required YouTube libraries aren't installed\n            ValueError: If the URL is not a valid YouTube video URL\n        \"\"\"\n        try:\n            from youtube_transcript_api import YouTubeTranscriptApi\n        except ImportError as e:\n            raise ImportError(\n                \"YouTube support requires youtube-transcript-api. \"\n                \"Install with: uv add youtube-transcript-api\"\n            ) from e\n\n        video_url = source.source\n        video_id = self._extract_video_id(video_url)\n\n        if not video_id:\n            raise ValueError(f\"Invalid YouTube URL: {video_url}\")\n\n        metadata: dict[str, Any] = {\n            \"source\": video_url,\n            \"video_id\": video_id,\n            \"data_type\": \"youtube_video\",\n        }\n\n        try:\n            api = YouTubeTranscriptApi()\n            transcript_list = api.list(video_id)\n\n            try:\n                transcript = transcript_list.find_transcript([\"en\"])\n            except Exception:\n                try:\n                    transcript = transcript_list.find_generated_transcript([\"en\"])\n                except Exception:\n                    transcript = next(iter(transcript_list))","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/rag/loaders/youtube_video_loader.py#L21-L57","documentation":"ValueError from the video loader's _extract_video_id returning None — the URL does not contain a parseable YouTube video ID. The static helper matches the standard watch?v=, youtu.be/, /shorts/, and embed URL shapes; anything else (including channel URLs) yields None and trips this check before any network call.","triggerScenarios":"Passing a channel URL (youtube.com/@handle) or playlist URL to the video loader; URLs where the ID parameter is empty or truncated (watch?v=); youtu.be links with extra path segments; URLs with malformed query strings that defeat parsing.","commonSituations":"Mixing up the video and channel loaders; LLM-generated URLs that look plausible but have malformed query params; URLs copy-pasted with the v parameter dropped by a truncating chat client; shortened share links mangled by markdown formatting.","solutions":["Use a canonical video URL: https://www.youtube.com/watch?v=VIDEOID or https://youtu.be/VIDEOID with an 11-character ID.","For channels, switch to the YouTube channel loader.","Pre-validate with your own extraction (e.g. regex for [\\w-]{11} after v= or youtu.be/) before calling load.","Log the exact URL received — invisible truncation or HTML entity encoding (&amp; instead of &) is a frequent culprit."],"exampleFix":"# before\nloader.load(SourceContent(path=\"https://www.youtube.com/@handle\"))  # not a video\n\n# after\nloader.load(SourceContent(path=\"https://www.youtube.com/watch?v=dQw4w9WgXcQ\"))","handlingStrategy":"validation","validationCode":"import re\n\nVIDEO_ID = re.compile(r\"(?:[?&]v=|youtu\\.be/|/shorts/|/embed/)([A-Za-z0-9_-]{11})\")\n\ndef extract_video_id(url: str) -> str | None:\n    m = VIDEO_ID.search(url)\n    return m.group(1) if m else None\n\ndef is_video_url(url: str) -> bool:\n    return extract_video_id(url) is not None","typeGuard":null,"tryCatchPattern":"try:\n    result = yt_video_loader.load(src)\nexcept ValueError as e:\n    if \"Invalid YouTube URL\" in str(e):\n        log.warning(\"unparseable youtube url: %r\", url)\n        skip(src)\n    raise","preventionTips":["Pre-extract the 11-char video ID yourself and rebuild a canonical watch URL.","HTML-decode URLs (&amp; -> &) before validation.","Send channel-form URLs to the channel loader, not this one."],"tags":["youtube","url-validation","rag"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}