{"record":{"id":"aaa9fc1a92b34d41","repo":"run-llama/llama_index","slug":"include-tables-missing-tables-not-found-in-datab","errorCode":null,"errorMessage":"include_tables {missing_tables} not found in database","messagePattern":"include_tables (.+?) not found in database","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/utilities/sql_wrapper.py","lineNumber":75,"sourceCode":"        self._engine = engine\n        self._schema = schema\n        if include_tables and ignore_tables:\n            raise ValueError(\"Cannot specify both include_tables and ignore_tables\")\n\n        self._inspector = inspect(self._engine)\n\n        # including view support by adding the views as well as tables to the all\n        # tables list if view_support is True\n        self._all_tables = set(\n            self._inspector.get_table_names(schema=schema)\n            + (self._inspector.get_view_names(schema=schema) if view_support else [])\n        )\n\n        self._include_tables = set(include_tables) if include_tables else set()\n        if self._include_tables:\n            missing_tables = self._include_tables - self._all_tables\n            if missing_tables:\n                raise ValueError(\n                    f\"include_tables {missing_tables} not found in database\"\n                )\n        self._ignore_tables = set(ignore_tables) if ignore_tables else set()\n        if self._ignore_tables:\n            missing_tables = self._ignore_tables - self._all_tables\n            if missing_tables:\n                raise ValueError(\n                    f\"ignore_tables {missing_tables} not found in database\"\n                )\n        usable_tables = self.get_usable_table_names()\n        self._usable_tables = set(usable_tables) if usable_tables else self._all_tables\n\n        if not isinstance(sample_rows_in_table_info, int):\n            raise TypeError(\"sample_rows_in_table_info must be an integer\")\n\n        self._sample_rows_in_table_info = sample_rows_in_table_info\n        self._indexes_in_table_info = indexes_in_table_info\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/utilities/sql_wrapper.py#L57-L93","documentation":"When include_tables is given, SQLWrapper verifies every requested table actually exists in the database (tables plus views if view_support=True). Any table in include_tables that the inspector cannot find raises ValueError listing the missing names, protecting downstream text-to-SQL from hallucinating over nonexistent tables.","triggerScenarios":"SQLDatabase(engine, include_tables=['users', 'acounts']) where 'acounts' is a typo; referencing tables in a non-default schema without passing schema=; listing views while view_support=False (views are then not in _all_tables); case-mismatched table names on case-sensitive backends.","commonSituations":"Typos or stale table lists after a schema migration renamed/dropped tables; pointing the engine at the wrong database or schema; environments (dev vs prod) with divergent schemas.","solutions":["List the real tables first: print(db.get_usable_table_names()) or insp.get_table_names(), then copy exact names into include_tables.","Pass schema='my_schema' if tables live outside the default schema, and view_support=True if you need views.","Match identifier case exactly on backends like Postgres (quoted identifiers) or Snowflake."],"exampleFix":"# before\n db = SQLDatabase(engine, include_tables=['users', 'acounts'])  # typo -> ValueError\n\n# after\n print(SQLDatabase(engine).get_usable_table_names())  # ['users', 'accounts', ...]\n db = SQLDatabase(engine, include_tables=['users', 'accounts'])","handlingStrategy":"validation","validationCode":"from sqlalchemy import inspect\n\ndef filter_include_tables(engine, include_tables, schema=None, view_support=False):\n    insp = inspect(engine)\n    existing = set(insp.get_table_names(schema=schema))\n    if view_support:\n        existing |= set(insp.get_view_names(schema=schema))\n    missing = set(include_tables or []) - existing\n    if missing:\n        raise ValueError(f'These tables do not exist: {sorted(missing)}. '\n                         f'Available: {sorted(existing)}')\n    return list(existing & set(include_tables))","typeGuard":"def include_tables_exist(engine, include_tables, schema=None) -> bool:\n    existing = set(inspect(engine).get_table_names(schema=schema))\n    return set(include_tables) <= existing","tryCatchPattern":"try:\n    db = SQLDatabase(engine, include_tables=tables)\nexcept ValueError as e:\n    if 'include_tables' in str(e) and 'not found' in str(e):\n        available = SQLDatabase(engine).get_usable_table_names()\n        tables = [t for t in tables if t in available]\n        db = SQLDatabase(engine, include_tables=tables)\n    else:\n        raise","preventionTips":["Always derive table lists from get_usable_table_names() instead of hand-typing.","Pass schema= and view_support=True when tables/views live outside defaults.","Re-validate include lists after schema migrations in CI."],"tags":["sql","schema-validation","text-to-sql","value-error"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}