BerriAI/litellm · error · RuntimeError

Error getting table info

Error message

Error getting table info: {exc}

What it means

get_table_info runs a small information_schema query describing the LiteLLM_DailyUserSpend columns and wraps query_raw in try/except, re-raising as RuntimeError('Error getting table info: ...') with the cause chained. It exists as a diagnostics helper for the Focus export pipeline, so its failure usually indicates the same underlying problems as the usage query: connectivity, permissions, or catalog access.

Solutions

  1. Read __cause__ for the underlying Prisma/Postgres error
  2. Verify database connectivity and that prisma_client is connected before probing
  3. Grant the DB role SELECT on LiteLLM_DailyUserSpend and read on information_schema
  4. Use this endpoint deliberately as a pre-flight check before get_usage_data

Example fix

# before
info = await db.get_table_info()

# after
try:
    info = await db.get_table_info()
except RuntimeError:
    logger.exception('Focus table probe failed; cause=%s', sys.exc_info()[1].__cause__)
    raise
Defensive patterns

Strategy: try-catch

Validate before calling

async def table_probe(db: FocusLiteLLMDatabase) -> dict[str, Any] | None:
    try:
        return await db.get_table_info()
    except RuntimeError:
        return None

Try / catch

try:
    info = await db.get_table_info()
except RuntimeError as e:
    logger.error('table probe failed; cause=%s', e.__cause__)
    info = None  # diagnostics only; do not fail the export job on probe failure

Prevention

When it happens

Trigger: Database unreachable when the diagnostics call runs; the DB role lacks read access to information_schema.columns; Prisma client disconnected (proxy shutting down) during the call.

Common situations: Health-check scripts calling get_table_info against a misconfigured replica; export tooling probing schema right after proxy startup before Prisma finished connecting; hardened DB roles with catalog permissions revoked.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/b54fc70e416fe05c. Report an issue: GitHub.

Appendix: source

Thrown at litellm/integrations/focus/database.py:117

            return pl.DataFrame(db_response, infer_schema_length=None)
        except Exception as exc:
            raise RuntimeError(f"Error retrieving usage data: {exc}") from exc

    async def get_table_info(self) -> dict[str, Any]:
        """Return metadata about the spend table for diagnostics."""
        client: Final = self._ensure_prisma_client()

        info_query: Final = """
        SELECT column_name, data_type, is_nullable
        FROM information_schema.columns
        WHERE table_name = 'LiteLLM_DailyUserSpend'
        ORDER BY ordinal_position;
        """
        try:
            columns_response: Final = await client.db.query_raw(info_query)
            return {"columns": columns_response, "table_name": "LiteLLM_DailyUserSpend"}
        except Exception as exc:
            raise RuntimeError(f"Error getting table info: {exc}") from exc

View on GitHub (pinned to 77b7c6c40c)