CoachnestCoachnest
Sign InGet Started
Back to course

Prompt Engineering Mastery: From Fundamentals to Production

…
—
Contents
1

What Is Prompt Engineering?

ReadingFree
2

How Large Language Models Actually Work

ReadingFree
3

Tokens, Context Windows, Temperature & Sampling

Reading11m
4

The Anatomy of a Great Prompt

Reading13m
5

Module 1 Knowledge Check

Quiz8m
6

Zero-Shot, One-Shot & Few-Shot Prompting

Reading12m
7

Role & Persona Prompting

Reading9m
8

Instruction Clarity, Delimiters & Decomposition

Reading11m
9

Controlling the Output Format

Reading10m
10

Module 2 Knowledge Check

Quiz8m
11

Chain-of-Thought Prompting

Reading12m
12

Self-Consistency & Tree-of-Thought

Reading11m
13

ReAct — Reasoning + Acting with Tools

Reading12m
14

Structured Output with JSON Schemas

Reading11m
15

Module 3 Knowledge Check

Quiz8m
16

Retrieval-Augmented Generation (RAG)

Reading13m
17

Prompt Templates, Variables & Chaining

Reading11m

Tool / Function Calling Patterns

Reading12m
19

Project — Build a Customer Support Assistant

Reading14m
20

Module 4 Knowledge Check

Quiz8m
21

Evaluating Prompt Quality

Reading12m
22

Prompt Injection & Security

Reading12m
23

Reducing Hallucinations

Reading10m
24

Cost, Latency & Optimization

Reading10m
25

Final Assessment — Prompt Engineering Mastery

Quiz15m
←→navigate lessons
Chapter 4 of 5·Module 4 · Building Real Applications
Lesson 18 of 25Reading12 min

Tool / Function Calling Patterns

#Tool / Function Calling Patterns¶

The production form of ReAct (Module 3): the model requests, your code executes.

The Contract¶

You declare tools with JSON schemas. The model decides whether and how to call them and returns a structured call. You run it, return the result, the model continues.

json
11 lines
1{
2  "name": "get_order_status",
3  "description": "Look up the current status of a customer's order. Use when the user asks where their order is or about delivery.",
4  "parameters": {
5    "type": "object",
6    "properties": {
7      "order_id": { "type": "string", "description": "The order ID, e.g. 'A1234'" }
8    },
9    "required": ["order_id"]
10  }
11}

The Description IS a Prompt¶

The model selects tools and fills arguments using the name + description + parameter descriptions. These are prompt engineering, not afterthoughts:

WeakStrong
"name": "func1""name": "get_order_status"
"description": "gets stuff""description": "Look up order status. Use when the user asks about delivery or where their order is."
order_id: stringorder_id: "The order ID, e.g. 'A1234'" (with example)

The Full Loop¶

1. Send user message + tool schemas 2. Model returns: tool_call(get_order_status, {order_id:"A1234"}) 3. Your code executes the real function 4. Send the tool result back to the model 5. Model produces the final natural-language answer

Patterns & Guardrails¶

  • Force / restrict tool use when needed (e.g. "must call search before answering factual questions").
  • Parallel tool calls: modern models can request several at once — execute concurrently, return all results.
  • Validate every argument before executing. The model can hallucinate IDs or out-of-range values. Never pass model output straight into a DB query or shell.
  • Keep observations small. Summarise large tool outputs before returning them or you'll exhaust context.
  • Handle tool errors gracefully: return a structured error the model can reason about ("ORDER_NOT_FOUND") rather than crashing.

Mini Worked Example¶

User: "Where's order A1234?" → model calls get_order_status({order_id:"A1234"}) → your DB returns {status:"shipped", eta:"2026-05-20"} → model: "Your order A1234 has shipped and should arrive around May 20, 2026."

Security note: Tool calling is an injection surface. Treat all model-produced arguments as untrusted input — validate and sanitise (deep dive: Module 5).

Previous

Prompt Templates, Variables & Chaining

Next

Project — Build a Customer Support Assistant

Use ← → arrow keys to navigate between lessons