{"record":{"id":"5b977de6bdc8965d","repo":"run-llama/llama_index","slug":"cannot-specify-both-include-tables-and-ignore-tabl","errorCode":null,"errorMessage":"Cannot specify both include_tables and ignore_tables","messagePattern":"Cannot specify both include_tables and ignore_tables","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/utilities/sql_wrapper.py","lineNumber":60,"sourceCode":"\n    def __init__(\n        self,\n        engine: Engine,\n        schema: Optional[str] = None,\n        metadata: Optional[MetaData] = None,\n        ignore_tables: Optional[List[str]] = None,\n        include_tables: Optional[List[str]] = None,\n        sample_rows_in_table_info: int = 3,\n        indexes_in_table_info: bool = False,\n        custom_table_info: Optional[dict] = None,\n        view_support: bool = False,\n        max_string_length: int = 300,\n    ):\n        \"\"\"Create engine from database URI.\"\"\"\n        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()","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/utilities/sql_wrapper.py#L42-L78","documentation":"SQLDatabase (via its internal SQLWrapper) lets you scope the visible schema with either include_tables (allowlist) or ignore_tables (blocklist), but not both - the combination is ambiguous. Supplying non-empty lists for both parameters raises ValueError at construction time, before any connection introspection is reused.","triggerScenarios":"Constructing SQLDatabase(engine, include_tables=['users'], ignore_tables=['logs']); also when config-driven code fills in both defaults (e.g. from settings that define an inclusion set and an exclusion set) rather than leaving one as None.","commonSituations":"Text-to-SQL pipelines configured from YAML/env where both keys are populated; refactoring from ignore-only to include-only scoping and forgetting to remove the old key; passing empty-list defaults [''] truthiness mistakes.","solutions":["Choose one strategy: keep include_tables and drop ignore_tables (or vice versa).","In config-driven code, treat empty/blank values as absent: include_tables=include or None.","If both lists exist logically, compute the effective allowlist yourself and pass only include_tables."],"exampleFix":"# before\n db = SQLDatabase(engine, include_tables=['users', 'orders'], ignore_tables=['logs'])\n\n# after\n db = SQLDatabase(engine, include_tables=['users', 'orders'])\n # or, if excluding from a known full set:\n db = SQLDatabase(engine, ignore_tables=['logs'])","handlingStrategy":"validation","validationCode":"def resolve_table_scope(include_tables, ignore_tables):\n    if include_tables and ignore_tables:\n        raise ValueError('Choose include_tables OR ignore_tables, not both')\n    return include_tables or None, ignore_tables or None","typeGuard":"def table_scope_is_exclusive(include_tables, ignore_tables) -> bool:\n    return not (bool(include_tables) and bool(ignore_tables))","tryCatchPattern":"try:\n    db = SQLDatabase(engine, include_tables=inc, ignore_tables=ign)\nexcept ValueError as e:\n    if 'Cannot specify both' in str(e):\n        db = SQLDatabase(engine, include_tables=inc)  # allowlist wins\n    else:\n        raise","preventionTips":["Treat blank config values as absent: include_tables=cfg.get('include') or None.","Document that scoping is allowlist-XOR-blocklist in config templates.","Add a startup validation step for SQL database configuration objects."],"tags":["sql","sqlalchemy","table-scoping","value-error"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}