run-llama/llama_index · error · ValueError
include_tables {missing_tables} not found in database
Error message
include_tables {missing_tables} not found in database What it means
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.
Source
Thrown at llama-index-core/llama_index/core/utilities/sql_wrapper.py:75
self._engine = engine
self._schema = schema
if include_tables and ignore_tables:
raise ValueError("Cannot specify both include_tables and ignore_tables")
self._inspector = inspect(self._engine)
# including view support by adding the views as well as tables to the all
# tables list if view_support is True
self._all_tables = set(
self._inspector.get_table_names(schema=schema)
+ (self._inspector.get_view_names(schema=schema) if view_support else [])
)
self._include_tables = set(include_tables) if include_tables else set()
if self._include_tables:
missing_tables = self._include_tables - self._all_tables
if missing_tables:
raise ValueError(
f"include_tables {missing_tables} not found in database"
)
self._ignore_tables = set(ignore_tables) if ignore_tables else set()
if self._ignore_tables:
missing_tables = self._ignore_tables - self._all_tables
if missing_tables:
raise ValueError(
f"ignore_tables {missing_tables} not found in database"
)
usable_tables = self.get_usable_table_names()
self._usable_tables = set(usable_tables) if usable_tables else self._all_tables
if not isinstance(sample_rows_in_table_info, int):
raise TypeError("sample_rows_in_table_info must be an integer")
self._sample_rows_in_table_info = sample_rows_in_table_info
self._indexes_in_table_info = indexes_in_table_info
View on GitHub (pinned to afd0fef371)
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.
Example fix
# before db = SQLDatabase(engine, include_tables=['users', 'acounts']) # typo -> ValueError # after print(SQLDatabase(engine).get_usable_table_names()) # ['users', 'accounts', ...] db = SQLDatabase(engine, include_tables=['users', 'accounts'])
Defensive patterns
Strategy: validation
Validate before calling
from sqlalchemy import inspect
def filter_include_tables(engine, include_tables, schema=None, view_support=False):
insp = inspect(engine)
existing = set(insp.get_table_names(schema=schema))
if view_support:
existing |= set(insp.get_view_names(schema=schema))
missing = set(include_tables or []) - existing
if missing:
raise ValueError(f'These tables do not exist: {sorted(missing)}. '
f'Available: {sorted(existing)}')
return list(existing & set(include_tables)) Type guard
def include_tables_exist(engine, include_tables, schema=None) -> bool:
existing = set(inspect(engine).get_table_names(schema=schema))
return set(include_tables) <= existing Try / catch
try:
db = SQLDatabase(engine, include_tables=tables)
except ValueError as e:
if 'include_tables' in str(e) and 'not found' in str(e):
available = SQLDatabase(engine).get_usable_table_names()
tables = [t for t in tables if t in available]
db = SQLDatabase(engine, include_tables=tables)
else:
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ignore_tables {missing_tables} not found in database
- Invalid context table names: {context_keys - set(self.sql_da
- Cannot specify both include_tables and ignore_tables
- Statement {command!r} is invalid SQL.\nError: {exc.orig}
- sql_database must be provided.
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/aaa9fc1a92b34d41.
Report an issue: GitHub.