BerriAI/litellm · error · ValueError
Invalid file path : contains URL special characters
Error message
Invalid file path {file_path!r}: contains URL special characters What it means
Before building the BitBucket src URL, _sanitize_file_path rejects any file path containing '#' or '?'. Those characters start a URL fragment/query respectively and would silently truncate or redirect the request to a different resource, so they are treated as invalid input rather than being percent-encoded (every other segment character IS encoded, so spaces and unicode are fine).
Solutions
- Strip the query/fragment: branch selection belongs in bitbucket_config (branch key), not the path
- Rename the file if it genuinely contains '#' or '?' in its name
- Pass clean repo-relative paths like 'prompts/triage.prompt'
- Validate/normalize user-supplied paths before they reach the client
Example fix
// before
client.get_file_content("prompts/triage.prompt?at=feature%2Fx")
// after (branch goes in config, path stays bare)
BitBucketClient({"workspace": "acme", "repository": "prompts",
"access_token": tok, "branch": "feature/x"})
client.get_file_content("prompts/triage.prompt") Defensive patterns
Strategy: validation
Validate before calling
def is_clean_repo_path(p: str) -> bool:
return bool(p) and "#" not in p and "?" not in p and ".." not in p.split("/")
if not is_clean_repo_path(file_path):
raise ValueError(f"refusing to fetch path with URL special characters or traversal: {file_path!r}") Type guard
def is_clean_repo_path(p: str) -> bool:
"""True when the path contains no '#', '?', or '..' segments."""
return bool(p) and "#" not in p and "?" not in p and ".." not in p.split("/") Prevention
- Never paste URLs from the BitBucket web UI as paths — strip '?at=...' query parts
- Put branch selection in bitbucket_config, never in the file path
- Validate user/LLM-supplied paths against the same two rules before calling the client
- Encode nothing yourself: the client percent-encodes every other character
When it happens
Trigger: Passing 'prompts/step#2.prompt' or 'triage.prompt?version=3' to get_file_content/list_files; UI or LLM-generated paths that carry query syntax; porting code from the BitBucket web UI where '?at=branch' URLs are normal and assuming the API accepts them too.
Common situations: Developers copy file URLs from bitbucket.org (which include ?at=refs%2Fheads%2Fmain) instead of the bare repo-relative path; templating systems that append cache-busting query strings.
Related errors
- Invalid file path : path traversal detected
- Access denied to directory
- Access denied to file
- Authentication failed. Check your BitBucket access token…
- bitbucket_config is required for BitBucket prompt…
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/e6b6c8e6ba91048c.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/integrations/bitbucket/bitbucket_client.py:15
"""
BitBucket API client for fetching .prompt files from BitBucket repositories.
"""
import base64
import urllib.parse
from typing import Any, Final
from litellm.llms.custom_httpx.http_handler import HTTPHandler
def _sanitize_file_path(file_path: str) -> str:
"""Reject path traversal and URL-encode each path segment."""
if "#" in file_path or "?" in file_path:
raise ValueError(f"Invalid file path {file_path!r}: contains URL special characters")
parts: Final = file_path.split("/")
for part in parts:
if part == "..":
raise ValueError(f"Invalid file path {file_path!r}: path traversal detected")
return "/".join(urllib.parse.quote(part, safe="") for part in parts)
class BitBucketClient:
"""
Client for interacting with BitBucket API to fetch .prompt files.
Supports:
- Authentication with access tokens
- Fetching file contents from repositories
- Team-based access control through BitBucket permissions
- Branch-specific file fetching
"""
View on GitHub (pinned to 77b7c6c40c)