Home > Workload Solutions > Data Analytics > White Papers > Multimodal RAG Chatbot Powered by Dell Data Lakehouse > 9. SQL Results Retrieval and Conversion
The DDAE processes the SQL queries and returns tabular results. These results represent structured information extracted from the database.
The LLM converts the tabular results into natural language, making the structured data understandable and usable in the context of the chatbot’s response.
# Function to convert SQL query results to natural language
def sql_to_text(results, query):
# Construct input prompt for LLM
input_prompt = f"Convert the following SQL query result into a natural language description.\n\nSQL Query: {query}\n\nResults: {results}\n\nDescription:"
# Tokenize and generate a natural language description
inputs = tokenizer(input_prompt, return_tensors="pt")
outputs = model.generate(**inputs)
description = tokenizer.decode(outputs[0], skip_special_tokens=True)
# Extract the description (usually found after the prompt)
description = description.split("Description:")[1].strip()
return description
# Convert SQL query results to natural language
sql_description = sql_to_text(result_df, refined_sql_queries)
# Output the natural language description
print("Natural Language Description:", description)