Beginners Resources

What Is Prompt Engineering? A Practical Guide for Data & AI Practitioners

Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

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.

Table of Contents

Learning Objectives

  • Define prompt engineering and understand why it matters.
  • Identify key components of effective prompts (context, instruction, constraints, examples).
  • Apply popular prompt patterns such as Chain-of-Thought, Few-Shot, and Role Prompting.
  • Troubleshoot common LLM failure modes and refine prompts iteratively.
  • Integrate prompt engineering into real-world workflows—e.g., writing SQL in Galaxy’s AI copilot.

1. What Is Prompt Engineering?

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.

1.1 Why Does It Matter?

  • Reliability: Small changes in wording can swing model outputs from brilliant to baffling.
  • Cost & Latency: Concise, well-structured prompts reduce token usage and response time.
  • Safety: Clear instructions lower the risk of sensitive data leakage or policy violations.
  • Governance: Repeatable prompts create audit trails—essential in regulated industries.

2. Anatomy of a High-Quality Prompt

Most effective prompts contain four building blocks. Use the mnemonic C.I.C.E.Context, Instruction, Constraints, Examples.

  1. Context: Background the model needs. E.g., “You are a senior data engineer.”
  2. Instruction: The task: “Explain the difference between INNER JOIN and LEFT JOIN.”
  3. Constraints: Output format, style, or length: “Respond in two bullet points.”
  4. Examples: One or more input–output pairs that demonstrate the right style.

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)

3. Core Prompt Patterns

Below are battle-tested patterns you can mix and match.

3.1 Zero-Shot Prompting

Simply instruct the model without examples. Use when tasks are simple or well known.

“Summarize this email in one sentence.”

3.2 Few-Shot Prompting

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:

3.3 Chain-of-Thought (CoT)

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...”

3.4 Role Prompting

Assign the model a persona: “You are a meticulous SQL linter.” Roles modulate tone and domain knowledge.

3.5 ReAct (Reason + Act)

An advanced pattern that alternates reasoning and acting on a tool (search API, calculator). Popular in agentic frameworks like LangChain.

4. Hands-On: Your First Prompt Engineering Lab

We’ll use Python and the OpenAI SDK. Feel free to swap in any LLM provider.

4.1 Setup

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)

4.2 Exercise

  1. Rewrite the prompt to add a real-world analogy.
  2. Add a constraint: return markdown with a code block.
  3. Compare token counts using response.usage.

5. Prompt Engineering for SQL in Galaxy

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.

5.1 Scenario

You need a query that returns churned customers in the last 30 days.

  1. Highlight the relevant tables in Galaxy’s schema sidebar (e.g., customers, subscriptions).
  2. Invoke copilot (Cmd + I) and paste an instruction-only prompt:
    “List customer_id, email, and churn_date for customers who churned in the last 30 days.”
  3. Galaxy stitches in context: database name, table columns, and sample rows.
  4. Copilot responds with an optimized SQL snippet:

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.”

6. Common Pitfalls & Troubleshooting

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.

7. Real-World Applications

  • Data Documentation: Auto-generate column descriptions from names.
  • Code Review: LLM suggests optimizations and catches anti-patterns.
  • Customer Support: Draft SQL fixes for common errors in submitted queries.
  • Analytics: Turn natural language KPIs into validated SQL via endorsed prompts in Galaxy.

8. Practice Challenges

  1. Design a Chain-of-Thought prompt that teaches someone the difference between OLTP and OLAP.
  2. Create a Few-Shot prompt that converts plain English filter descriptions into WHERE clauses.
  3. Iteratively refine a role prompt until Galaxy’s copilot returns a query using window functions and explains each clause in comments.

Key Takeaways

  • Prompt engineering is a structured, repeatable process—not guesswork.
  • Use C.I.C.E. to plan prompts: Context, Instruction, Constraints, Examples.
  • Patterns like Few-Shot and Chain-of-Thought dramatically improve output quality.
  • Iterate quickly: small tweaks → big gains.
  • Tools like Galaxy embed domain context, making prompts safer and more accurate for SQL tasks.

Next Steps

  • Read the OpenAI Prompt Engineering Guide.
  • Save your favorite prompts in a Galaxy Collection for team reuse.
  • Experiment with temperature (creativity) and max_tokens (length) to see their effects.
  • Join the Galaxy community Slack to compare prompt techniques with peers.

Check out some other beginners resources