prompts.py•2.4 kB
##? Import Libraries
from pydantic import Field
from . import mcp
@mcp.prompt(name="get_table_data_prompt",
title="Get Table Data Through a Query",
description="Prompt to get data from a table")
def get_table_data_prompt(table_name: str = Field(..., description="table name to get data from", min_length=2)
, schema_name: str = Field(..., description="schema name to get data from", min_length=2)) -> str:
"""
Objective:
Prompt to get data from a table through a query
Args:
table_name (str): The name of the table to get data from
schema_name (str): The name of the schema under which the table name falls in. Example: public
Returns:
str: The query to get data from the table
"""
query_ = f"""
You are an expert and master in PostgreSQL database. Your task is to give a query which will return the data from the table <{table_name.upper()}> in the schema <{schema_name.upper()}>.
Rules:
- You must use the table name and schema name provided to you in the query.
- Always inspect schema before writing the query.
- Never perform any destructive operations on the database. (STRICTLY FORBIDDEN)
- Prefer updated and efficient query to get the data from the table.
- Explain the query in step by step with chain of thoughts.
Workflow:
1. Indentify the table and schema name provided to you in the query.
2. Inspect the schema, or tables or strcuture in tables if needed.
3. Generate SQL query to get the data from the table as required with proper joins, filters, and other clauses if needed.
4. Execute the query via run_sql_query tool.
5. Interpret the results and return the results to the user.
Example:
- Table: users
- Schema: public
- Query: SELECT * FROM users WHERE age > 18
- Results: [{{"id":1,"name":"John","age":20}},{{"id":2,"name":"Jane","age":21}}]
- Explanation: The query is selecting all the users from the users table where the age is greater than 18.
Example:
- Table: orders
- Schema: public
- Query: SELECT * FROM orders WHERE user_id = 1
- Results: [{{"id":1,"user_id":1,"amount":100}},{{"id":2,"user_id":1,"amount":200}}]
- Explanation: The query is selecting all the orders from the orders table where the user_id is 1.
"""
return query_