crewAIInc/crewAI · error · ValueError
Query cannot be empty
Error message
Query cannot be empty
What it means
DatabricksQueryToolSchema.validate_input is a Pydantic model_validator(mode='after') that rejects any query input which is None, empty, or only whitespace, raising ValueError('Query cannot be empty'). Pydantic surfaces it as a ValidationError when the tool's input schema is constructed, i.e. before any SQL is sent to Databricks.
Source
Thrown at lib/crewai-tools/src/crewai_tools/tools/databricks_query_tool/databricks_query_tool.py:64
)
db_schema: str | None = Field(
None,
description="Databricks schema name (optional, defaults to configured schema)",
)
warehouse_id: str | None = Field(
None,
description="Databricks SQL warehouse ID (optional, defaults to configured warehouse)",
)
row_limit: int | None = Field(
1000, description="Maximum number of rows to return (default: 1000)"
)
@model_validator(mode="after")
def validate_input(self) -> DatabricksQueryToolSchema:
"""Validate the input parameters."""
# Ensure the query is not empty
if not self.query or not self.query.strip():
raise ValueError("Query cannot be empty")
# Add a LIMIT clause to the query if row_limit is provided and query doesn't have one
if self.row_limit and "limit" not in self.query.lower():
self.query = f"{self.query.rstrip(';')} LIMIT {self.row_limit};"
return self
class DatabricksQueryTool(BaseTool):
"""A tool for querying Databricks workspace tables using SQL.
This tool executes SQL queries against Databricks tables and returns the results.
It requires Databricks authentication credentials to be set as environment variables.
Authentication can be provided via:
- Databricks CLI profile: Set DATABRICKS_CONFIG_PROFILE environment variable
- Direct credentials: Set DATABRICKS_HOST and DATABRICKS_TOKEN environment variables
View on GitHub (pinned to 754d7323be)
Solutions
- Pass a valid SQL string: tool.run(query="SELECT * FROM my_table LIMIT 10").
- If an LLM drives the tool, tighten the tool description / agent prompt so the model always emits a concrete SQL query.
- Guard the call site: strip and check the query before invoking the tool (see defense below).
- Inspect the generated query string (log it) if a template was supposed to fill it in.
Example fix
# before
tool.run(query=user_input) # user_input == "" -> ValueError
# after
q = (user_input or "").strip()
if not q:
raise ValueError("Refusing to call DatabricksQueryTool with an empty query")
tool.run(query=q) Defensive patterns
Strategy: validation
Validate before calling
def validate_query(q: str | None) -> str:
q = (q or "").strip()
if not q:
raise ValueError("Cannot run DatabricksQueryTool with an empty query")
return q
query = validate_query(raw_llm_output) Type guard
def is_non_empty_query(q: object) -> bool:
return isinstance(q, str) and len(q.strip()) > 0 Try / catch
from pydantic import ValidationError
try:
result = tool.run(query=q)
except ValidationError as e:
if "Query cannot be empty" in str(e):
q = fallback_query # e.g. "SELECT 1"
result = tool.run(query=q)
else:
raise Prevention
- Strip and assert the query is non-empty before invoking the tool.
- When LLMs generate the query, validate the tool arguments schema-side and retry with a corrective prompt.
- Unit-test the empty/whitespace input path so it fails at your boundary, not inside the tool.
When it happens
Trigger: Calling DatabricksQueryTool with query="", query=" ", or omitting query; an LLM agent emitting an empty tool call argument; a template/variable interpolation producing an empty string (e.g. f"SELECT ... WHERE id={missing}").
Common situations: Agent produces malformed tool arguments; upstream prompt returns an empty query; default parameter accidentally set to empty string; whitespace-only query from trimmed user input.
Related errors
- action={self.action!r} requires 'path'.
- action='append' requires 'content'. Pass the chunk to append
- action='move' requires 'destination'.
- action='find' requires 'pattern' (text to search for inside
- action='search' requires 'pattern' (glob, e.g. '*.py').
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/05bfbf49c458dddd.
Report an issue: GitHub.