You type a prompt, run it, see a failing check, tweak one instruction, then rerun until it passes. It turns prompt advice into reps. You learn faster because the feedback loop is tight and each notebook focuses on one skill. No screenshots or templates, just run the cell and watch the output change.
Here is the free preview. You are going to clone the Anthropic Cookbook, install the Python SDK, and run one notebook. The notebooks are plain JupyterLab (a browser-based notebook) files, so you can read and edit everything.
First install the SDK and Jupyter, then clone the repo. Use a clean virtual environment if you like, but you can also run it system-wide while testing.
bash
python3 -m pip install --upgrade anthropic jupyterlab
git clone https://github.com/anthropic/anthropic-cookbook.git
cd anthropic-cookbook
Export your key so the checks can call Claude (Anthropic’s AI model). Any Claude model works. Haiku is fast and cheap for drills.
bash
export ANTHROPIC_API_KEY=sk-ant-1234567890abcdef
jupyter lab
Verify the SDK sees your key before you open a notebook.
bash
python3 -c "import anthropic, os; print('OK', anthropic.__version__, bool(os.getenv('ANTHROPIC_API_KEY')))
"
Inside JupyterLab, open a prompt engineering notebook, run the first cell, and read the failing check. Change one instruction in the system message, run again, and watch the answer clean up. Stop here if you only want the quick win. The full guide below adds platform setup, config tips, and fixes for common errors.
Here is the free preview. You are going to clone the Anthropic Cookbook, install the Python SDK, and run one notebook. The notebooks are plain JupyterLab (a browser-based notebook) files, so you can read and edit everything.
First install the SDK and Jupyter, then clone the repo. Use a clean virtual environment if you like, but you can also run it system-wide while testing.
bash
python3 -m pip install --upgrade anthropic jupyterlab
git clone https://github.com/anthropic/anthropic-cookbook.git
cd anthropic-cookbook
Export your key so the checks can call Claude (Anthropic’s AI model). Any Claude model works. Haiku is fast and cheap for drills.
bash
export ANTHROPIC_API_KEY=sk-ant-1234567890abcdef
jupyter lab
Verify the SDK sees your key before you open a notebook.
bash
python3 -c "import anthropic, os; print('OK', anthropic.__version__, bool(os.getenv('ANTHROPIC_API_KEY')))
"
Inside JupyterLab, open a prompt engineering notebook, run the first cell, and read the failing check. Change one instruction in the system message, run again, and watch the answer clean up.
Setup
macOS
- Ensure Python 3.10+ is installed.
- Optional, install via Homebrew if you want isolation.
bash
brew install python
python3 -V
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade anthropic jupyterlab
Clone the repo and start JupyterLab.
bash
git clone https://github.com/anthropic/anthropic-cookbook.git
cd anthropic-cookbook
export ANTHROPIC_API_KEY=sk-ant-1234567890abcdef
jupyter lab
Linux (Debian/Ubuntu)
bash
sudo apt update && sudo apt install -y python3 python3-pip git
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade anthropic jupyterlab
git clone https://github.com/anthropic/anthropic-cookbook.git
cd anthropic-cookbook
export ANTHROPIC_API_KEY=sk-ant-1234567890abcdef
jupyter lab
Windows
Use PowerShell.
bash
winget install -e --id Python.Python.3.11
py -3.11 -m pip install --upgrade pip
py -3.11 -m pip install --upgrade anthropic jupyterlab
git clone https://github.com/anthropic/anthropic-cookbook.git
cd anthropic-cookbook
setx ANTHROPIC_API_KEY "sk-ant-1234567890abcdef"
# Close and reopen PowerShell so the variable is loaded
py -3.11 -m jupyter lab
Verify
Quick smoke test that the SDK works and the key is set.
bash
python3 - <<'PY'
import os
from anthropic import Anthropic
print('Key present:', bool(os.getenv('ANTHROPIC_API_KEY')))
client = Anthropic()
resp = client.messages.create(
model="claude-3-haiku-20240307",
max_tokens=32,
temperature=0,
messages=[{"role": "user", "content": "Reply with the word PASS only."}]
)
text = resp.content[0].text.strip()
print('Model:', resp.model)
print('Output:', text)
print('PASS check:', text == 'PASS')
PY
Expected output shape:
Key present: True
Model: claude-3-haiku-20240307
Output: PASS
PASS check: True
Open JupyterLab, browse to a prompt engineering notebook, and run cells top to bottom. You will see a failing assertion or a simple check. Edit the system message or step instructions, rerun, and watch the check flip to passing.
Configuration tips
- Pick the right model during drills. Use
claude-3-haiku-20240307for speed, then confirm your final prompt onclaude-3-sonnet-20240229before shipping. - Lock down randomness for testing. Set
temperature=0and add a deterministic instruction like “answer with only PASS or FAIL.” Your checks stop flapping. - Cap tokens to catch runaways. Set
max_tokensto a tight budget, for example 128 during tests, then increase if the task is long. - Separate system rules from task input. Put policies and format rules in
system, keep the task inuser. You can then swap tasks without touching the guardrails. - Save good runs. At the end of a passing cell, write the final prompt and output to a file so you can diff changes later.
py
from pathlib import Path
Path(".runs").mkdir(exist_ok=True)
with open(".runs/last_pass.txt", "w") as f:
f.write("SYSTEM:\n" + system + "\n\nUSER:\n" + user + "\n\nOUTPUT:\n" + text)
Troubleshooting
- 401 Unauthorized or invalid API key
- Symptom: anthropic.AuthenticationError or 401. - Fix: ensure the env var is set in the same shell that starts Jupyter. On macOS or Linux run export ANTHROPIC_API_KEY=... then jupyter lab. On Windows run setx ANTHROPIC_API_KEY "...", restart PowerShell, then py -m jupyter lab.
- Jupyter sees no environment variable
- Symptom: bool(os.getenv('ANTHROPIC_API_KEY')) prints False in a notebook while True in your shell. - Fix: start Jupyter from the same terminal after exporting the key. Or set it inside the notebook once for that session:
py
import os
os.environ["ANTHROPIC_API_KEY"] = "sk-ant-1234567890abcdef"
- SSL or TLS error on macOS
- Symptom: SSL certificate verify failed on first API call. - Fix: run the macOS certificate install tool that comes with Python. Then retry.
bash
/Applications/Python\ 3.11/Install\ Certificates.command
- 429 rate limit or timeouts
- Symptom: requests throttled or slow. - Fix: switch drills to claude-3-haiku-20240307, add small sleeps between runs, and keep max_tokens low while testing.
When it beats paid prompt packs
- Onboarding a team. Open a notebook, assign one drill, and ask for a passing run. You see exactly what they changed and why, not just a template pasted into chat.
- Debugging long prompts. The checks force you to tighten the system message and task steps. You see the smallest change that flips a fail to a pass.
- Teaching format discipline. You wire in a pass condition like “return valid JSON.” The loop punishes vague wording and rewards precise instructions.
- Building eval habits. The lab is already a notebook. Add a few asserts and you now have repeatable checks you can run in CI or before release.
Sources
-
Want a hand?
Book a 30-min call.
Walk through your stack with us. We'll find the bottleneck and map out the exact wiring you need — free.