Skip to content

Commit

Permalink
fix(nl-responder): prevent halucination when no data is returned (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
BartMiki authored Jul 4, 2024
1 parent 953d8a1 commit e3fec18
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/dbally/nl_responder/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,24 @@ def __init__(
examples: List[FewShotExample] = None,
) -> None:
"""
Constructs a new IQLGenerationPromptFormat instance.
Constructs a new NLResponsePromptFormat instance.
Args:
question: Question to be asked.
filters: List of filters exposed by the view.
results: List of records, where dictonary keys store column names.
examples: List of examples to be injected into the conversation.
"""
super().__init__(examples)
self.question = question
self.results = pd.DataFrame.from_records(results).to_markdown(index=False, headers="keys", tablefmt="psql")

if results:
self.results = pd.DataFrame.from_records(results).to_markdown(index=False, headers="keys", tablefmt="psql")
else:
self.results = (
"The query returned 0 rows. The table has no data. Don't halucinate responses. "
"Make sure to inform the user, that there are no data points, that satisfy their question."
"Be brief in your response and remember to answer the question correctly."
)


class QueryExplanationPromptFormat(PromptFormat):
Expand Down

0 comments on commit e3fec18

Please sign in to comment.