Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DH-4728] Better error messages for responses #216

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions dataherald/sql_generator/create_sql_query_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
from dataherald.types import Response, SQLQueryResult


def format_error_message(response: Response, error_message: str) -> Response:
# Remove the complete query
if error_message.find("[") > 0 and error_message.find("]") > 0:
error_message = (
error_message[0 : error_message.find("[")]
+ error_message[error_message.rfind("]") + 1 :]
)
response.sql_generation_status = "INVALID"
response.response = ""
response.sql_query_result = None
response.error_message = error_message
return response


def create_sql_query_status(
db: SQLDatabase, query: str, response: Response, top_k: int = None
) -> Response:
Expand Down Expand Up @@ -54,8 +68,6 @@ def create_sql_query_status(
"Sensitive SQL keyword detected in the query."
) from e
except Exception as e:
response.sql_generation_status = "INVALID"
response.response = ""
response.sql_query_result = None
response.error_message = str(e)
response = format_error_message(response, str(e))

return response