liveBook · Manning

Prompt engineering

As explained in Learn AI Data Engineering

Prompt engineering is the deliberate design and refinement of inputs provided to an AI model to influence the quality, format, or behavior of its outputs.

Prompt engineering is the deliberate design and iterative refinement of model instructions so an AI system produces useful behavior within a defined workflow. It is not merely asking a question: the prompt communicates rules of engagement, identifies important fields, sets priorities, explains ambiguity, and specifies the expected result. In data work, this can move matching logic from rigid code into natural-language guidance while keeping the human responsible for the rules. section 7.3

A useful prompt supplies the context the model cannot safely infer. Long SQL schemas, JSON structures, and multi-step requests consume a limited context window; when essential details fall outside it, a model can lose relationships, forget constraints, or fabricate missing information. Supply schema documentation, DDL, or an ERD when needed; split a large task into focused interactions; restate critical entity relationships; and validate the resulting code against known definitions. section 2.3 section 2.0

Design prompts as an explicit, testable interface rather than an open-ended request:

  • State the role and the task boundary, such as resolving an incoming activity record to a known customer. section 7.3
  • Name the fields the model must use and indicate how they should be considered, including canonical sources or field weighting when appropriate. section 7.3
  • Specify the output contract: required fields, a confidence value, and reasoning that makes the decision reviewable. section 7.3
  • Keep instructions focused. An underspecified prompt invites unintended assumptions, while an overloaded prompt can confuse the model or exceed its token budget. section 7.3 section 2.3
  • Run generated code and decisions through schema and business-rule checks. Treat output as a first draft, then use feedback loops to correct errors. section 2.0

Entity resolution with a structured prompt

For an incoming customer activity record, frame the model as an entity-resolution assistant. Provide the incoming record and known customers, then instruct it to compare name, email, device ID, IP address, and coding language. Require the best matching customer’s name and email, a confidence score, and reasoning. This makes the matching criteria visible and allows an uncertain result—for example, a name and language match that conflicts with email, device, and IP—to be reviewed instead of silently accepted. Calibrate the instructions through repeated trials as records and business expectations evolve. section 7.3 section 2.0

Prompt quality is operational work. The goal is not a perfect instruction written once, but calibration toward behavior that works for the actual system. As datasets evolve, revise the context, priorities, and output requirements; preserve validation around the model; and use AI to reduce repetitive work while retaining human judgment for critical decisions. section 7.3 section 1.0 section 2.0

Listing 7.8 AI - Entity Resolution
import openai  #A
import os  #A
from dotenv import load_dotenv  #A
from pydantic import BaseModel  #B
 
load_dotenv()  #B
openai.api_key = os.getenv("OPENAI_API_KEY")  #B
 
# Define a structured output model for entity resolution  #B
class EmailMatch(BaseModel):  #B
    name: str  #B
    email: str  #B
    confidence: float  #B
    reasoning: str  #B
 
# Define the system prompt with resolution instruction  #C
system_prompt = """
You are an entity resolution assistant for a developer productivity platform.
A new activity record has arrived, and you must determine which known customer it most likely belongs to.
Use all available information: name, email, device_id, IP address, and top coding language.
Compare this incoming activity to the list of known customers. Identify the best match, and return:
- The matched customer's name and email
- A confidence score from 0 to 1
- A short explanation of your reasoning, including which features contributed most to the match
""".strip()  #C
 
# Format the full input payload  #D
user_message = {
    "incoming_activity": incoming_activity,
    "customers": customers
}  #D
 
# Call the OpenAI API with schema enforcement  #E
completion = openai.beta.chat.completions.parse(  #E
    model="gpt-4o",  #E
    messages=[  #E
        {"role": "system", "content": system_prompt},  #E
        {"role": "user", "content": f"{user_message}"}  #E
    ],
    response_format=EmailMatch  #E
)
 
# Extract and display the structured response  #F
match = completion.choices[0].message.parsed.dict()  #F
 
# Format and Print  #F
print(f"Best match: {match['name']} ({match['email']})")
print(f"Confidence: {match['confidence']:.2f}")
print("Reasoning:")
print(match['reasoning']) 
 

This implementation shows a system prompt paired with a Pydantic output model, making match identity, confidence, and reasoning explicit fields for downstream review. section 7.3

How Learn AI Data Engineering covers it

How deep it goes
Works through prompt instructions, context limits, structured output, iteration, and validation rather than model internals.
Examples
Uses Pagila schema context and customer-record matching with names, emails, device IDs, IP addresses, coding languages, confidence, and reasoning.
What it assumes
Assumes familiarity with data schemas and business context while supplying practical prompting and validation steps.
What you can do after
Apply it via an AI coding workflow to create focused, schema-grounded prompts and reviewable structured results.
How it connects
Connects prompt engineering with entity resolution, context windows, structured data extraction, hallucinations, and human validation.

Also explained in

Compare how 51 books explain prompt engineering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn AI Data Engineering. The section links point to the parts of the book it draws on.