class TableSelectionResult
A dataclass that encapsulates the results of a table selection operation, including selected tables, reasoning, confidence score, and suggested joins.
/tf/active/vicechatdev/full_smartstat/two_pass_sql_workflow.py
20 - 25
simple
Purpose
This dataclass serves as a structured container for the output of a table selection pass in a database query generation system. It stores which tables were selected for a query, the reasoning behind the selection, a confidence score indicating the certainty of the selection, and any suggested join operations between tables. This is typically used in natural language to SQL conversion systems where an LLM needs to determine which database tables are relevant for answering a user's question.
Source Code
class TableSelectionResult:
"""Result of table selection pass"""
selected_tables: List[str]
reasoning: str
confidence: float
suggested_joins: List[str]
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
- | - |
Parameter Details
selected_tables: A list of strings representing the names of database tables that were selected as relevant for the query. Each string should be a valid table name from the database schema.
reasoning: A string containing the explanation or rationale for why these particular tables were selected. This provides transparency and helps with debugging or understanding the selection logic.
confidence: A float value (typically between 0.0 and 1.0) representing the confidence level in the table selection. Higher values indicate greater certainty that the selected tables are correct for the query.
suggested_joins: A list of strings describing potential join operations between the selected tables. Each string typically describes a relationship or join condition between two or more tables.
Return Value
Instantiating this class returns a TableSelectionResult object with the four specified attributes. Since this is a dataclass, it automatically generates an __init__ method that accepts all four parameters and returns an instance of TableSelectionResult. The object is immutable by default unless frozen=False is specified in the dataclass decorator.
Class Interface
Methods
__init__(selected_tables: List[str], reasoning: str, confidence: float, suggested_joins: List[str]) -> None
Purpose: Initializes a new TableSelectionResult instance with the provided table selection data. This method is automatically generated by the @dataclass decorator.
Parameters:
selected_tables: List of table names selected for the queryreasoning: Explanation for the table selectionconfidence: Confidence score for the selection (typically 0.0-1.0)suggested_joins: List of suggested join conditions between tables
Returns: None (constructor)
__repr__() -> str
Purpose: Returns a string representation of the TableSelectionResult instance. Automatically generated by @dataclass.
Returns: String representation showing all attributes and their values
__eq__(other: object) -> bool
Purpose: Compares two TableSelectionResult instances for equality based on all attributes. Automatically generated by @dataclass.
Parameters:
other: Another object to compare with
Returns: True if all attributes are equal, False otherwise
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
selected_tables |
List[str] | List of database table names that were selected as relevant for the query | instance |
reasoning |
str | Textual explanation of why these tables were selected | instance |
confidence |
float | Numerical confidence score indicating certainty of the selection (typically 0.0 to 1.0) | instance |
suggested_joins |
List[str] | List of suggested join conditions or relationships between the selected tables | instance |
Dependencies
dataclassestyping
Required Imports
from dataclasses import dataclass
from typing import List
Usage Example
from dataclasses import dataclass
from typing import List
@dataclass
class TableSelectionResult:
selected_tables: List[str]
reasoning: str
confidence: float
suggested_joins: List[str]
# Create an instance
result = TableSelectionResult(
selected_tables=['users', 'orders', 'products'],
reasoning='Selected users table for customer info, orders for transaction data, and products for item details',
confidence=0.92,
suggested_joins=[
'users.id = orders.user_id',
'orders.product_id = products.id'
]
)
# Access attributes
print(result.selected_tables) # ['users', 'orders', 'products']
print(result.confidence) # 0.92
print(result.reasoning) # 'Selected users table for...'
print(result.suggested_joins) # ['users.id = orders.user_id', ...]
Best Practices
- This is a dataclass, so it automatically generates __init__, __repr__, __eq__, and other methods. No need to define them manually.
- The confidence value should typically be normalized between 0.0 and 1.0 for consistency.
- The selected_tables list should contain valid table names that exist in the database schema being queried.
- The suggested_joins should be formatted consistently (e.g., 'table1.column = table2.column') for easier parsing.
- Since this is a dataclass without frozen=True, instances are mutable. Consider adding frozen=True to the decorator if immutability is desired.
- This class is typically instantiated as the return value from a table selection function or method in a larger query generation pipeline.
- The reasoning field is valuable for debugging and explaining AI decisions to end users.
- When using this in a pipeline, check the confidence score to determine if additional validation or user confirmation is needed for low-confidence selections.
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class SqlGenerationResult 74.9% similar
-
class IterationResult 69.6% similar
-
class AnalysisResult 59.9% similar
-
class AnalysisResult_v1 59.5% similar
-
class AnalysisResult_v1 59.4% similar