← Back to The Associate Track

// What's Next · Done · The Associate Track

Prompt Engineering with the OpenAI API

Completed Nov 04, 2026 · 4 hrs

These notes cover prompt engineering foundations and the OpenAI API, principles for clear prompts, advanced strategies such as few-shot and chain-of-thought prompting, business applications, and chatbot development with system messages and external context.

Foundations and API Recap

  • Prompt engineering: Crafting prompts or instructions given to large language models to obtain desired responses.
  • Chat Completions: The main API endpoint used for chatting.
  • Message roles: User, assistant, and system labels attached to every API message.
  • Temperature: A value between 0 and 2 that controls the randomness of the answer.
  • max_tokens: A parameter that controls the desired response length.
  • get_response: A wrapper function that sends a prompt to the API and returns the response.

Key Prompt Principles

  • Clear and precise prompts: Guiding the model to the best results with unambiguous instructions.
  • Action verbs: Explicit verbs such as write, complete, explain, describe, or evaluate that steer the task.
  • Detailed instructions: Specifying context, output length, format and style, and audience.
  • Output length limits: max_tokens enforces a strict cap, while prompt limits can be bypassed but keep responses complete.
  • Delimiters: Markers such as triple backticks that isolate input text so the model can locate it.
  • F-strings: Python formatted strings that embed variable content into a prompt.

Advanced Prompting Strategies

  • Few-shot prompting: Giving the model example question-answer pairs so it learns how to answer.
  • Zero, one, and few-shot: The technique name depends on whether zero, one, or several examples are provided.
  • Multi-step prompting: Breaking a goal into smaller ordered steps to improve accuracy.
  • Chain-of-thought prompting: Asking the model to present reasoning steps before the final answer.
  • Self-consistency prompting: Generating multiple chain-of-thought responses and selecting the majority vote.
  • Iterative refinement: Building, testing, analyzing, and improving prompts in repeated cycles.

Business Applications

  • Text summarization: Condensing text into a shorter coherent version while preserving essential meaning.
  • Text expansion: Generating text from a few ideas or bullet points.
  • Text transformation: Changing text while keeping the same information, covering translation, tone adjustment, and writing improvement.
  • Text classification: Assigning one of several potential categories, such as sentiment.
  • Entity extraction: Extracting specific entities such as names, places, organizations, and dates.
  • Code generation and explanation: Creating code from a problem description or input-output examples, then explaining it.

Chatbot Development

  • System message: Defines the chatbot's purpose, response guidelines, and behavior guidance.
  • Role-playing prompts: Instructing the chatbot to adopt a specific role with matching tone, vocabulary, and behavior.
  • External context: Supplying missing information the model lacks from training cut-offs or non-public sources.
  • Dual-prompt get_response: A modified function that accepts a system prompt and a user prompt.

// Module notes

Foundations and API Recap

Prompts are the lever this whole module pulls: craft them well and the model delivers, craft them poorly and it wanders. Prompt engineering means writing prompts or instructions for large language models to get desired responses, like a recipe that combines ingredients into a dish.

  • The OpenAI Python package talks to the API with your key; Chat Completions is the main chat endpoint.
  • Every message carries one of three roles: user, assistant, or system.
  • Temperature (0 to 2) controls randomness, and max_tokens controls response length.
  • A get_response wrapper turns a prompt into a one-line call.

Why it matters: with roles and controls set, improving the model means editing the prompt, not the code.

Key Prompt Principles

Clear and precise prompts give the best results, so the first move is precision: name the action and spell out the details.

  • Use action verbs like write, explain, or evaluate; avoid ambiguous ones like understand, think, feel, or know.
  • Specify context, output length, format and style, and audience.
  • Cap length with max_tokens for a strict limit, or prompt instructions that can be bypassed but keep responses complete.
  • Delimit input with markers like triple backticks, place instructions first, and name the delimiters.

Watch for the trade-off: a hard token cap can truncate an answer, while a soft instruction can be ignored.

Structured Outputs and Advanced Strategies

Three levers do the heavy lifting here: structured outputs, conditional prompts, and iterative refinement.

  • Request tables, lists, structured paragraphs, or a custom format from instructions, output format, and delimited input.
  • Add if-else conditions, like generating a title only for English text.
  • Few-shot prompting supplies example question-answer pairs; zero-shot uses none, one-shot uses one.
  • Multi-step prompting breaks a goal into ordered steps; chain-of-thought asks for reasoning before the answer.
  • Self-consistency samples several chain-of-thought responses, then takes a majority vote.

What to watch: examples and reasoning raise accuracy, but a flawed example or a wrong step still propagates.

Prompt Engineering for Business Applications

Business value comes from a repeatable pattern: delimited input, a stated job, and a specified output.

  • Summarization condenses text with output limits, structure, and focus.
  • Expansion turns bullet points into text with tone, length, and audience.
  • Transformation covers translation, tone adjustment, and grammar or writing improvement.
  • Classification assigns categories like sentiment; entity extraction pulls names, places, organizations, and dates.
  • Code generation uses a problem description, language, and format, or input-output examples.
  • Code explanation ranges from a one-sentence summary to a detailed chain-of-thought walkthrough.

Watch for: each task changes the details, not the underlying prompt discipline.

Prompt Engineering for Chatbot Development

User questions are hard to predict, so a chatbot's behavior must be set before the conversation starts, in the system message.

  • Define the chatbot's purpose, response guidelines, and conditional behavior in the system message.
  • A dual-prompt get_response function accepts a system and a user prompt.
  • Role-playing prompts assign a role, adjusting tone, vocabulary, and behavior to fit it.
  • External context fills gaps from training cut-offs or non-public information.
  • Provide it through sample conversations or delimited text in the system prompt, which suits only small contexts.

What to watch: these methods hold for small contexts; large ones need more sophisticated techniques.

In plain terms

Prompt engineering is cooking with a very literal chef: you pick the ingredients, write the recipe, and specify the plating, and the model follows your instructions exactly. Clear prompts, examples, and constraints turn a general-purpose model into a dependable assistant for summaries, chatbots, and code. The model is not the bottleneck, the prompt is.

Worth sitting with

  • When does adding more examples stop helping and start to muddy the answer?
  • How would you tell a weak prompt apart from a model that simply does not know?
  • Once a chatbot's context outgrows a few examples, what takes the place of the system prompt?

// Where this fits

The concepts above are the ones this module turns on, and the notes below explain each in turn. The course page carries the whole track, and the certificate page carries the plan it belongs to.