{"record":{"id":"459d3ee1d48076b9","repo":"run-llama/llama_index","slug":"context-dict-must-be-provided-there-is-currently","errorCode":null,"errorMessage":"context_dict must be provided. There is currently no table context.","messagePattern":"context_dict must be provided\\. There is currently no table context\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/indices/struct_store/sql_query.py","lineNumber":237,"sourceCode":"        # there's a ' in the value (e.g. \"I'm\")\n        response = response.replace(\"\\\\'\", \"''\")\n        return response.strip()\n\n    def _get_table_context(self, query_bundle: QueryBundle) -> str:\n        \"\"\"\n        Get table context.\n\n        Get tables schema + optional context as a single string. Taken from\n        SQLContextContainer.\n\n        \"\"\"\n        if self._sql_context_container.context_str is not None:\n            tables_desc_str = self._sql_context_container.context_str\n        else:\n            table_desc_list = []\n            context_dict = self._sql_context_container.context_dict\n            if context_dict is None:\n                raise ValueError(\n                    \"context_dict must be provided. There is currently no \"\n                    \"table context.\"\n                )\n            for table_desc in context_dict.values():\n                table_desc_list.append(table_desc)\n            tables_desc_str = \"\\n\\n\".join(table_desc_list)\n\n        return tables_desc_str\n\n    def _run_with_sql_only_check(self, sql_query_str: str) -> Tuple[str, Dict]:\n        \"\"\"Don't run sql if sql_only is true, else continue with normal path.\"\"\"\n        if self._sql_only:\n            metadata: Dict[str, Any] = {}\n            raw_response_str = sql_query_str\n        else:\n            raw_response_str, metadata = self._sql_database.run_sql(sql_query_str)\n\n        return raw_response_str, metadata","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/indices/struct_store/sql_query.py#L219-L255","documentation":"NLStructStoreQueryEngine._get_table_context() raises ValueError('context_dict must be provided...') when the SQLContextContainer has neither context_str nor context_dict. The engine builds the schema prompt by preferring container.context_str; if that is None it falls back to joining every value of context_dict, and if context_dict is also None there is no table context at all to put in the prompt, so it aborts rather than sending the LLM an empty schema.","triggerScenarios":"Constructing SQLContextContainer() with no arguments and passing it to NLStructStoreQueryEngine(index, context_container=...); manually building a container and setting only context_str=None fields; upgrading from older versions where the container auto-populated defaults.","commonSituations":"Hand-rolling SQLContextContainer instead of using SQLContextContainerBuilder; copy-pasting code that creates SQLContextContainer(context_dict={}) correctly but dropping the dict; partial initialization where context was assigned to a different variable than the one passed.","solutions":["Use SQLContextContainerBuilder(sql_database, table_dict) and pass builder.get_sql_context_container() — it always yields a container with context_str set.","Or set at least one field explicitly: SQLContextContainer(context_str='table city_stats: ...') or SQLContextContainer(context_dict={'city_stats': 'city population table'}).","If you rely on the index default, simply omit context_container — the index builds a default container from the table schema."],"exampleFix":"# before\ncontainer = SQLContextContainer()  # both fields None\nengine = NLStructStoreQueryEngine(index, context_container=container)\n\n# after\nfrom llama_index.core.indices.struct_store import SQLContextContainerBuilder\nbuilder = SQLContextContainerBuilder(sql_database, table_dict={\"city_stats\": \"city population table\"})\nengine = NLStructStoreQueryEngine(index, context_container=builder.get_sql_context_container())","handlingStrategy":"validation","validationCode":"from llama_index.core.indices.struct_store.sql_query import SQLContextContainer\n\ndef has_table_context(c: SQLContextContainer) -> bool:\n    return c.context_str is not None or bool(c.context_dict)","typeGuard":"def is_usable_context_container(c) -> bool:\n    return c is not None and (c.context_str is not None or bool(getattr(c, \"context_dict\", None)))","tryCatchPattern":"try:\n    response = query_engine.query(q)\nexcept ValueError as e:\n    if \"context_dict must be provided\" in str(e):\n        query_engine = NLStructStoreQueryEngine(\n            index, context_container=SQLContextContainer(context_str=DEFAULT_SCHEMA_STR)\n        )\n        response = query_engine.query(q)\n    else:\n        raise","preventionTips":["Prefer SQLContextContainerBuilder.get_sql_context_container() over hand-built containers.","If building SQLContextContainer manually, always set context_str or a non-empty context_dict.","Omit the container entirely to let the index derive default schema context."],"tags":["sql","prompt-context","config","llama-index"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}