haive.agents.rag.db_rag.sql_rag.prompts ======================================= .. py:module:: haive.agents.rag.db_rag.sql_rag.prompts .. autoapi-nested-parse:: Prompt templates for SQL RAG Agent. This module contains all the prompt templates used throughout the SQL RAG workflow. Each prompt is carefully crafted to guide the LLM through specific tasks while maintaining consistency and accuracy. The prompts follow a structured format with clear system instructions and user templates that include necessary context variables. .. rubric:: Example Using prompts with LangChain:: >>> from langchain_core.prompts import ChatPromptTemplate >>> from haive.agents.rag.db_rag.sql_rag.prompts import GENERATE_SQL_PROMPT >>> >>> # Format prompt with variables >>> messages = GENERATE_SQL_PROMPT.format_messages( ... schema=db_schema, ... dialect="postgresql", ... question="Show top products", ... query_analysis=analysis_result ... ) >>> >>> # Use with LLM >>> llm = ChatOpenAI() >>> response = llm.invoke(messages) Attributes ---------- .. autoapisummary:: haive.agents.rag.db_rag.sql_rag.prompts.ANALYZE_QUERY_PROMPT haive.agents.rag.db_rag.sql_rag.prompts.ANSWER_GRADING_PROMPT haive.agents.rag.db_rag.sql_rag.prompts.GENERATE_FINAL_ANSWER_PROMPT haive.agents.rag.db_rag.sql_rag.prompts.GENERATE_SQL_PROMPT haive.agents.rag.db_rag.sql_rag.prompts.GUARDRAILS_PROMPT haive.agents.rag.db_rag.sql_rag.prompts.HALLUCINATION_CHECK_PROMPT haive.agents.rag.db_rag.sql_rag.prompts.VALIDATE_SQL_PROMPT Module Contents --------------- .. py:data:: ANALYZE_QUERY_PROMPT Prompt for analyzing natural language queries. This prompt guides the LLM to break down user questions into SQL components without generating the actual query. It helps identify: - Required tables and columns - JOIN operations needed - WHERE clause constraints - Aggregation functions - Query complexity Variables: schema: Database schema information dialect: SQL dialect (postgresql, mysql, etc.) question: User's natural language question :returns: SQLAnalysisOutput with structured analysis .. py:data:: ANSWER_GRADING_PROMPT Prompt for grading answer relevance. This prompt evaluates whether the generated answer actually addresses what the user asked, ensuring quality responses. Variables: question: Original question answer: Generated answer :returns: GradeAnswer with binary score .. py:data:: GENERATE_FINAL_ANSWER_PROMPT Prompt for generating natural language answers. This prompt converts raw SQL query results into user-friendly answers that directly address the original question. Variables: question: Original user question sql_query: Executed SQL query query_result: Raw query results :returns: String with natural language answer .. py:data:: GENERATE_SQL_PROMPT Prompt for generating SQL queries. This prompt converts natural language questions into executable SQL queries based on the analysis and schema information. It ensures: - Correct syntax for the specific dialect - Safe queries (SELECT only) - Proper use of JOINs and aggregations - Result limiting for safety - Meaningful result ordering Variables: schema: Database schema information dialect: SQL dialect question: User's question query_analysis: Analysis from previous step :returns: SQLQueryOutput with generated query .. py:data:: GUARDRAILS_PROMPT Prompt for domain relevance checking (guardrails). This prompt filters out irrelevant questions that aren't about database queries, preventing the agent from attempting to answer questions outside its scope. Variables: schema: Database schema tables: List of table names question: User's question :returns: GuardrailsOutput with decision and reason .. py:data:: HALLUCINATION_CHECK_PROMPT Prompt for detecting hallucinations in answers. This prompt ensures answers are grounded in actual query results and don't include fabricated information. Variables: question: Original question query_result: Actual data returned answer: Generated answer to check :returns: GradeHallucinations with binary score .. py:data:: VALIDATE_SQL_PROMPT Prompt for validating SQL queries. This prompt performs comprehensive validation including: - Syntax correctness - Schema compliance - JOIN validity - Aggregation rules - Performance considerations - Security checks Variables: schema: Database schema dialect: SQL dialect question: Original question sql_query: Query to validate :returns: SQLValidationOutput with errors and suggestions