{"record":{"id":"787340a2e233b2ad","repo":"run-llama/llama_index","slug":"sample-rows-in-table-info-must-be-an-integer","errorCode":null,"errorMessage":"sample_rows_in_table_info must be an integer","messagePattern":"sample_rows_in_table_info must be an integer","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/utilities/sql_wrapper.py","lineNumber":89,"sourceCode":"        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\n        self._custom_table_info = custom_table_info\n        if self._custom_table_info:\n            if not isinstance(self._custom_table_info, dict):\n                raise TypeError(\n                    \"table_info must be a dictionary with table names as keys and the \"\n                    \"desired table info as values\"\n                )\n            # only keep the tables that are also present in the database\n            intersection = set(self._custom_table_info).intersection(self._all_tables)\n            self._custom_table_info = {\n                table: info\n                for table, info in self._custom_table_info.items()\n                if table in intersection\n            }","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/utilities/sql_wrapper.py#L71-L107","documentation":"SQLWrapper validates that sample_rows_in_table_info (the number of example rows embedded in each table's context info for the LLM) is an int; passing anything else - a string like '3', a float, None - raises TypeError at construction time.","triggerScenarios":"SQLDatabase(engine, sample_rows_in_table_info='3') from unconverted config/env values; passing 3.0 (float) or a numpy integer on some paths; templated YAML that yields strings.","commonSituations":"Loading SQLDatabase settings from environment variables or YAML where everything is a string; notebook code passing a slider/widget value without int() conversion.","solutions":["Convert explicitly at the boundary: sample_rows_in_table_info=int(value).","Add schema validation (pydantic settings) for config so numeric fields arrive typed.","If you want no sample rows, pass the int 0 rather than None."],"exampleFix":"# before\n db = SQLDatabase(engine, sample_rows_in_table_info=os.environ['SAMPLE_ROWS'])  # '3' str\n\n# after\n db = SQLDatabase(engine, sample_rows_in_table_info=int(os.environ['SAMPLE_ROWS']))","handlingStrategy":"validation","validationCode":"def coerce_sample_rows(value) -> int:\n    if value is None:\n        return 3  # library default\n    n = int(value)\n    if n < 0:\n        raise ValueError('sample_rows_in_table_info must be >= 0')\n    return n\n\n# usage: SQLDatabase(engine, sample_rows_in_table_info=coerce_sample_rows(cfg['sample_rows']))","typeGuard":"def is_valid_sample_rows(value) -> bool:\n    return isinstance(value, int) and not isinstance(value, bool) and value >= 0","tryCatchPattern":"try:\n    db = SQLDatabase(engine, sample_rows_in_table_info=cfg['sample_rows'])\nexcept TypeError as e:\n    if 'must be an integer' in str(e):\n        db = SQLDatabase(engine, sample_rows_in_table_info=int(cfg['sample_rows']))\n    else:\n        raise","preventionTips":["int()-convert config/env values before passing them to SQLDatabase.","Use typed pydantic settings models for database configuration.","Remember None is not valid; use 0 to disable sample rows."],"tags":["sql","type-error","configuration"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}