ractogateway.pipelines.sql_analyst._models
Data models for SQLAnalystPipeline.
- exception ractogateway.pipelines.sql_analyst._models.ReadOnlyViolationError[source]
Bases:
ValueErrorRaised when generated SQL contains a write operation in force_read_only mode.
- exception ractogateway.pipelines.sql_analyst._models.RateLimitExceededError[source]
Bases:
RuntimeErrorRaised when the rate limiter denies a request for a given user.
- class ractogateway.pipelines.sql_analyst._models.PipelineUsage(**data)[source]
Bases:
BaseModelAggregated token usage across all LLM calls in the pipeline.
Tracks each step (SQL generation, pandas code generation, markdown answer generation) separately so you can see exactly where tokens are consumed.
Properties
- total_input_tokens:
Sum of all prompt tokens across every LLM step.
- total_output_tokens:
Sum of all completion tokens across every LLM step.
- total_tokens:
Grand total of every token consumed by the pipeline.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- sql_input_tokens: int
- sql_output_tokens: int
- pandas_input_tokens: int
- pandas_output_tokens: int
- answer_input_tokens: int
- answer_output_tokens: int
- property total_input_tokens: int
- property total_output_tokens: int
- property total_tokens: int
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class ractogateway.pipelines.sql_analyst._models.SQLAnalystResult(**data)[source]
Bases:
BaseModelResult returned by
SQLAnalystPipeline.All fields except
user_queryhave sensible defaults so that a partial result can be returned whensafe_mode=Trueand an error occurs.Fields
- user_query:
The original natural-language question.
- schema_used:
The database schema string that was passed to (or fetched for) the LLM.
- sql_query:
The generated (and possibly LIMIT-injected) SQL SELECT statement.
- columns:
Column names returned by the SQL query.
- row_count:
Number of rows in
raw_rows.- raw_rows:
All rows from the SQL result as a list of dicts.
- pandas_code:
The LLM-generated pandas analysis code (
Noneifrun_pandas=False).- pandas_result:
Output of executing
pandas_code— DataFrame, scalar, or any value assigned toresultinside the code.Noneifrun_pandas=False.- answer:
Rich Markdown answer written by the LLM, including a results table and key insights.
Noneifrun_answer=False.- chart_spec:
The
ChartSpecdict used to build the Plotly figure.Noneif no chart was requested.- plotly_figure:
A
plotly.graph_objects.Figureobject ready to call.show()or.to_html().Noneif no chart was requested or plotly is not installed.- usage:
Aggregated token counts for all LLM steps in the pipeline.
- error:
Set when
safe_mode=Trueand an exception occurs.Nonemeans the pipeline completed successfully.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- user_query: str
- schema_used: str
- sql_query: str
- row_count: int
- usage: PipelineUsage
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- to_csv(path=None)[source]
Export the raw SQL result rows to CSV.
Does not require pandas — uses the standard-library
csvmodule.
- to_json(path=None, *, indent=2)[source]
Export the raw SQL result rows to JSON.
- to_excel(path, *, sheet_name='Results')[source]
Export the raw SQL result rows to an Excel file.
Requires
pandasandopenpyxl:pip install ractogateway[pipelines-sql] openpyxl