{"record":{"id":"4639b22c0c25bb23","repo":"crewAIInc/crewAI","slug":"return-columns-cannot-be-empty-at-least-one-colum","errorCode":null,"errorMessage":"return_columns cannot be empty. At least one column must be specified for the SELECT query to be valid.","messagePattern":"return_columns cannot be empty\\. At least one column must be specified for the SELECT query to be valid\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/db2_search_tool.py","lineNumber":141,"sourceCode":"    limit: int = Field(\n        default=3,\n        ge=1,\n        le=100,\n        description=\"Number of documents to return. Must be between 1 and 100.\",\n    )\n\n    distance_metric: str = \"COSINE\"\n\n    max_distance: float | None = Field(\n        default=None,\n        ge=0.0,\n        description=\"Maximum allowed distance for results. Cannot be negative.\",\n    )\n\n    @model_validator(mode=\"after\")\n    def _validate_return_columns(self) -> DB2VectorSearchTool:\n        if not self.return_columns:\n            raise ValueError(\n                \"return_columns cannot be empty. At least one column must be specified \"\n                \"for the SELECT query to be valid.\"\n            )\n        return self\n\n    db2_package: Any = Field(default=None, description=\"IBM DB2 base package.\")\n    db2_dbi_package: Any = Field(default=None, description=\"IBM DB2 DBI package.\")\n\n    custom_embedding_fn: ImportString[Callable[[str], list[float]]] | None = Field(\n        default=None,\n        description=\"Optional custom embedding function.\",\n    )\n\n    connection: Any | None = None\n    dbi_connection: Any | None = None\n    cursor: Any | None = None\n    _openai_client: Any | None = None\n","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/db2_search_tool.py#L123-L159","documentation":"DB2VectorSearchTool._validate_return_columns is a Pydantic model_validator that rejects an empty return_columns list, because the tool builds a SELECT with those column names and SELECT with no columns is invalid SQL. The check runs at tool instantiation, so the tool object cannot even be constructed without at least one column. It is unrelated to connectivity or credentials.","triggerScenarios":"DB2VectorSearchTool(table_name='docs', vector_column='embedding', return_columns=[]) or omitting return_columns when its default is empty; passing return_columns=None; a config loader producing an empty list for a missing config key.","commonSituations":"YAML/env-driven configuration where the columns key is absent and the loader yields []; teams intending 'SELECT *' — not supported, columns must be listed explicitly; refactor that moved the columns argument and left an empty default.","solutions":["List at least one real column: return_columns=['content', 'metadata'].","If you wanted all columns, enumerate them explicitly in the list.","Fix the config loader so a missing key raises or defaults to a sensible non-empty list."],"exampleFix":"# before\ntool = DB2VectorSearchTool(table_name='docs', vector_column='embedding', return_columns=[])\n\n# after\ntool = DB2VectorSearchTool(table_name='docs', vector_column='embedding', return_columns=['id', 'content'])","handlingStrategy":"validation","validationCode":"def make_db2_tool(table: str, vector_col: str, columns: list[str] | None, **kw):\n    if not columns:\n        raise ValueError('return_columns cannot be empty — list the columns to SELECT')\n    return DB2VectorSearchTool(table_name=table, vector_column=vector_col,\n                               return_columns=columns, **kw)","typeGuard":"def is_nonempty_str_list(value: object) -> bool:\n    return isinstance(value, list) and bool(value) and all(isinstance(c, str) and c for c in value)","tryCatchPattern":"try:\n    tool = DB2VectorSearchTool(**cfg)\nexcept ValidationError as e:\n    if 'return_columns' in str(e):\n        cfg['return_columns'] = ['id', 'content']  # sensible default, retry construction\n        tool = DB2VectorSearchTool(**cfg)\n    else:\n        raise","preventionTips":["Fail fast in config loading when the columns key is missing — never default to [].","Enumerate columns explicitly; the tool does not support SELECT *.","Add a pydantic/TypedDict config model with min_length=1 on the columns field."],"tags":["db2","pydantic","validation","sql","vector-search","configuration"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}