This resource demystifies prompt engineering—the art of crafting inputs that guide large language models (LLMs) toward accurate, reliable outputs. You’ll learn foundational concepts, prompt patterns, common pitfalls, and how to practice your skills in everyday workflows, including Galaxy’s AI copilot for SQL.
Prompt engineering is the practice of designing, testing, and refining the text (or code) you send to a large language model so the model returns the result you need—consistently, safely, and efficiently. Think of it as UX design for AI: the prompt is the user interface between human intent and the model’s probabilistic reasoning.
Most effective prompts contain four building blocks. Use the mnemonic C.I.C.E.—Context, Instruction, Constraints, Examples.
You are a senior data engineer (Context).
Explain the difference between INNER JOIN and LEFT JOIN (Instruction).
Respond in two concise bullet points (Constraints).
Example:
Q: Difference between UNION and UNION ALL?
A: • UNION removes duplicates • UNION ALL keeps duplicates (Examples)
Below are battle-tested patterns you can mix and match.
Simply instruct the model without examples. Use when tasks are simple or well known.
“Summarize this email in one sentence.”
Provide 1-5 demonstrations so the model learns the mapping you expect.
User: Translate English to pirate speak.
###
Input: I had a great time at the party.
Output: Arr, I enjoyed meself at the gathering!
###
Input: The server is down.
Output:
Ask the model to think step by step. Improves reasoning, especially in math or logic.
“You are an expert tutor. Think step by step to solve the following problem...”
Assign the model a persona: “You are a meticulous SQL linter.” Roles modulate tone and domain knowledge.
An advanced pattern that alternates reasoning and acting on a tool (search API, calculator). Popular in agentic frameworks like LangChain.
We’ll use Python and the OpenAI SDK. Feel free to swap in any LLM provider.
pip install openai python-dotenvimport os, openai
openai.api_key = os.getenv("OPENAI_API_KEY")
prompt = """
You are a SQL mentor. Explain partition pruning in Snowflake in 50 words.
"""
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": prompt}],
)
print(response.choices[0].message.content)
response.usage
.Galaxy’s AI copilot is an LLM specialized for SQL. The same C.I.C.E. principles apply, but you can embed table context automatically. Below is an example workflow.
You need a query that returns churned customers in the last 30 days.
customers
, subscriptions
).SELECT c.customer_id,
c.email,
s.cancelled_at AS churn_date
FROM customers c
JOIN subscriptions s ON c.customer_id = s.customer_id
WHERE s.status = 'cancelled'
AND s.cancelled_at >= CURRENT_DATE - INTERVAL '30 days';
Tip: If output is wrong (e.g., missing a join), refine the prompt iteratively: “Use LEFT JOIN to include customers without subscriptions.”
IssueDiagnosisFixHallucinationModel invents columnsAdd schema-aware context or provide table definitions.Under-SpecificationVague answerClarify constraints: length, format, level of detail.OverloadPrompt too long, high costPrune context to essentials; reference external docs via URLs.Prompt DriftWorks today, fails tomorrowVersion-control prompts in Galaxy Collections or Git.