Utils
Utility modules for gllm-retrieval.
format_sql_query(query)
Format the SQL query to ensure it is correctly structured.
Removes the code block markdown from the SQL query and trims any leading or trailing whitespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query |
str
|
The SQL query output from the language model. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The formatted SQL query. |
validate_query(query, dialect='postgres')
Validates if the given string is an SQL statement using sqlglot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query |
str
|
The SQL query to be validated. |
required |
dialect |
str
|
The SQL dialect to be used for validation. Defaults to "postgres". |
'postgres'
|
Raises:
Type | Description |
---|---|
ValueError
|
If the query is not a valid SQL statement. |