{"record":{"id":"b4b7467eea761e6f","repo":"zylon-ai/private-gpt","slug":"at-least-one-sql-database-artifact-is-required","errorCode":null,"errorMessage":"At least one SQL database artifact is required.","messagePattern":"At least one SQL database artifact is required\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"private_gpt/components/tools/builders/database_query_builder.py","lineNumber":210,"sourceCode":"        name: str = DATABASE_QUERY_TOOL_NAME,\n        type: str = DATABASE_QUERY_TOOL_NAME + \"_v1\",\n        description: str = DATABASE_QUERY_TOOL_FN.metadata.description,\n        validate: ToolValidationMode = ToolValidationMode.LAZY,\n        runtime: Literal[\"client\", \"server\"] = \"server\",\n        blob_visibility: BlobVisibilityMode = BlobVisibilityMode.PUBLIC,\n    ) -> ToolSpec:\n        (\n            database_query_generator_cls,\n            error_query_result_cls,\n            query_result_cls,\n            query_result_type_cls,\n        ) = _load_database_query_dependencies()\n\n        sample_size = self.sample_size  # capture for closure\n\n        async def validate_sql() -> None:\n            if not sql_artifacts:\n                raise ValueError(\"At least one SQL database artifact is required.\")\n\n            query_gen = [\n                database_query_generator_cls(\n                    connection_string=sql_artifact.connection_string,\n                    ssl=sql_artifact.ssl,\n                    schemas=sql_artifact.schemas,\n                    # TODO: Meanwhile we validate the feature,\n                    # we set readonly to true to avoid accidental data changes\n                    is_readonly=True,\n                    enable_tables=sql_artifact.enable_tables,\n                    enable_views=sql_artifact.enable_views,\n                    enable_functions=sql_artifact.enable_functions,\n                    enable_procedures=sql_artifact.enable_procedures,\n                    description=sql_artifact.description,\n                    batch_size=self.settings.database_query.batch_size,\n                    timeout_seconds=self.settings.database_query.timeout_seconds,\n                    max_mb_result=self.settings.database_query.max_mb_result,\n                    cache=self.cache,","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/tools/builders/database_query_builder.py#L192-L228","documentation":"ValueError raised inside the validate_sql tool closure when sql_artifacts (the list of SQL database artifacts captured at build time) is empty. The tool validates connections before running queries, and with zero artifacts there is nothing to connect to, so it refuses up front.","triggerScenarios":"The database query tool spec is built with an empty sql_artifacts list (no SQLDatabaseArtifact in the context) and the agent then calls the validate_sql tool function.","commonSituations":"Chat context does not include any SQL database artifacts (user never attached a database); the artifact-filtering step upstream returned an empty list; tool was registered globally without per-request artifact wiring.","solutions":["Ensure the chat context includes at least one SQL database artifact with a valid connection_string before the tool runs.","Fix the upstream artifact resolution so sql_artifacts passed to the builder is non-empty.","If no database is attached for this request, do not expose/enable the database query tool in that toolset."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if not sql_artifacts:\n    raise ValueError(\"attach at least one SQLDatabaseArtifact to the context\")\n# or: only expose the tool when artifacts exist\nexpose_db_tool = bool(sql_artifacts)","typeGuard":"def has_sql_artifacts(context) -> bool:\n    return bool(getattr(context, \"sql_artifacts\", None))","tryCatchPattern":null,"preventionTips":["Conditionally register the database query tool per request, only when sql_artifacts is non-empty.","Validate the artifact list at tool-build time rather than inside the closure.","Log which artifacts were resolved so empty lists are traceable."],"tags":["database","validation","tool-input"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}