Spaces:
Runtime error
Runtime error
Download agents/analysis/backend/app/services/sql_guard.py from zaheer140/liveChatBotBackend: direct link, hf CLI and curl.
- Browser
- Download file 594 Bytes
-
https://huggingface.co/spaces/zaheer140/liveChatBotBackend/resolve/main/agents/analysis/backend/app/services/sql_guard.py
- Command line
-
hf download hf://spaces/zaheer140/liveChatBotBackend/agents/analysis/backend/app/services/sql_guard.py
-
curl -L -o sql_guard.py https://huggingface.co/spaces/zaheer140/liveChatBotBackend/resolve/main/agents/analysis/backend/app/services/sql_guard.py
594 Bytes
| from __future__ import annotations | |
| ALLOWED_SQL_PREFIXES = ("select", "with") | |
| BLOCKED_SQL_TOKENS = ("insert ", "update ", "delete ", "drop ", "alter ", "truncate ") | |
| def validate_read_only_sql(query: str) -> str: | |
| normalized = " ".join(query.strip().lower().split()) | |
| if not normalized.startswith(ALLOWED_SQL_PREFIXES): | |
| raise ValueError("Only read-only SELECT/WITH queries are allowed.") | |
| for token in BLOCKED_SQL_TOKENS: | |
| if token in normalized: | |
| raise ValueError(f"Blocked SQL token detected: {token.strip()}") | |
| return query.strip() | |