Skip to content

Commit

Permalink
[DH-5756] Raise an error when sql is not valid (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcjc712 authored Apr 26, 2024
1 parent 66688d1 commit fbd96ea
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion dataherald/api/types/requests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pydantic import BaseModel
from pydantic import BaseModel, validator
from sql_metadata import Parser

from dataherald.types import LLMConfig

Expand All @@ -17,6 +18,14 @@ class SQLGenerationRequest(BaseModel):
sql: str | None
metadata: dict | None

@validator("sql")
def validate_model_name(cls, v: str | None):
try:
Parser(v).tables # noqa: B018
except Exception as e:
raise ValueError(f"SQL {v} is malformed. Please check the syntax.") from e
return v


class StreamSQLGenerationRequest(BaseModel):
finetuning_id: str | None
Expand Down

0 comments on commit fbd96ea

Please sign in to comment.