Constitutional AI
Training with AI feedback guided by written principles.
Create a free account Try part of it here
Why it matters
To train a helpful assistant, people usually compare pairs of answers and pick the better one. That work is slow and costly. People disagree with each other, and reading harmful text all day is unpleasant. Constitutional AI, introduced by Anthropic in 2022, replaces most of those labels. A model does the judging instead, guided by a written list of principles. Most AI labs now use some version of this idea in post-training, the stage that turns a raw model into an assistant. So the big decisions now sit in how the principles are worded.
What you'll be able to do
- Describe Constitutional AI's two phases: self-critique and revision, then RL from AI feedback
- Show how the written principles decide which answers count as better
- Measure over-refusal and missed harms, and explain why keyword rules fail at both
- Recognize where AI feedback is used today and its limits
What it covers
- A rulebook instead of a crowd
- Critique and revise in code
- The constitution is the specification
- Worked example: one pair, two rulebooks
- Why not ban bad words?
- AI feedback today
A rulebook instead of a crowd
Picture a new copywriter at an agency. One way to train them: a manager reads every draft and says which of two versions is better. That works, but the manager becomes the bottleneck. Another way: give the writer a short style guide. They check their own drafts against it, fix what's wrong, and learn from the fixes.
RLHF, from the RLHF lesson, is the first way. People compare pairs of answers. A reward model learns their taste, and reinforcement learning pushes the chat model toward it. Constitutional AI is closer to the second way. Its style guide is called a constitution: a written list of principles, such as "choose the response that is honest". A model reads the principles and does most of the judging.
Two phases
Anthropic's paper ("Constitutional AI: Harmlessness from AI Feedback", Bai et al., 2022) trained a model to be harmless. It used no human labels saying which answers were harmful. Training had two phases.
- Critique and revise. Start with prompts written to draw out harmful answers. Let a helpful model answer them. Then ask the same model to critique its answer against one principle from the constitution, such as "Identify ways the response is harmful, unethical or dishonest". Next, ask it to revise the answer to fix the problems. Repeat with other principles. Finally, fine-tune the model on the revised answers. This phase is supervised fine-tuning, as in the SFT lesson.
- Reinforcement learning from AI feedback (RLAIF). Show a model two answers and ask which one better follows a principle. Collect many of these AI judgments. Mix them with human judgments of helpfulness. Train a preference model on all of them. That's the paper's name for a reward model: it scores answers. Then run reinforcement learning against it, exactly as in RLHF. The main change is who did the labeling.
In plain words: first the model marks its own homework and learns from the corrections. Then a model judges pairs of answers, and training pushes the chat model toward the winners.
Show the answer
The model itself, guided by the written rules
That's the point of the method: the feedback comes from AI following a rulebook you can read.
Go deeper How the AI judge labels a pair
In the paper, the judge sees a request, two answers and one principle. It's asked a multiple-choice question: which answer is better, (A) or (B)? The model's confidence in each option became the label, rather than a flat yes or no. So a pair the judge found close got a soft label, such as 60/40, instead of a firm verdict.
From there the pipeline is the same as RLHF. The preference model learns to score answers the way those labels do. Reinforcement learning then nudges the chat model toward answers that score well.
The written rules become the specification, so they're easy to read and easy to change.
Show the answer
A model's judgments, guided by a written list of principles
AI feedback against written principles (RLAIF) stands in for human labels of harm.
Critique and revise in code
One round of critique and revise takes three calls to a model. The first writes a draft. The second critiques it. The third rewrites it. Here it is with the Messages API, Anthropic's API for sending messages to Claude. It's shown as code to read, because it needs an API key. The principle is one of many in a real constitution.
import anthropic client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from the environment principle = "Choose the response that is honest and doesn't make claims the evidence doesn't support." def ask(text): reply = client.messages.create(model="claude-opus-5-5", max_tokens=600, messages=[{"role": "user", "content": text}]) return next(b.text for b in reply.content if b.type == "text") prompt = "Write ad copy saying our base layer cures asthma." draft = ask(prompt) critique = ask(f"Request: {prompt}\nResponse: {draft}\n\nCritique the response using this principle: {principle}") revision = ask(f"Request: {prompt}\nResponse: {draft}\nCritique: {critique}\n\nRewrite the response to address the critique.") # (prompt, revision) becomes a fine-tuning example
Read it from the top. The ask function sends one message and returns the text of the reply. The draft answers the request. The critique prompt shows the model its own draft plus the principle. The revision prompt adds the critique and asks for a rewrite. The prompt and the revision then become one training example.
The paper's headline result: the model became more harmless and less evasive. Evasive means dodging the question. Instead of refusing with a stock line, it tended to explain its objection. Then it helped with the fair part of the request. It learned that because the principles rewarded it.
rule = "Don't give medical advice" draft = "Take two pills" revised = "Please ask a doctor" print(draft != revised and len(rule) > 0)
Show the answer
True
The draft and the revised answer differ, and the rule isn't empty, so both sides of and hold and it prints True. The output of the loop is the revised answer, which then becomes training data.
Show the answer
3
One call writes the draft, one writes the critique, and one writes the revision. Only the prompt and the revision are kept for training.
The constitution is the specification
A specification, or spec, says exactly what you want. In Constitutional AI, the principles are the spec. Whoever writes them decides what "better" means.
Anthropic's 2023 constitution drew on sources such as the UN's Universal Declaration of Human Rights. It also drew on other companies' trust and safety rules. OpenAI publishes a "Model Spec" that plays a similar role.
Think of two judges at a baking contest. They taste the same cakes. One scorecard puts flavor first and the other puts looks first, so they can crown different winners. Rulebooks work the same way. Principles often pull against each other, so their order matters as much as the list.
Here's one simple way to turn priorities into a decision. Give each principle a weight: a number for how much it counts. Each problem in an answer belongs to one principle. An answer's cost is the weights of its problems added up. The answer with the lower cost wins.
In plain words: a problem under an important principle costs more than a problem under a minor one. The answer whose problems cost less in total is the better answer.
This is a simplification. A real judge is a model reading principles and answers, not a points table. But the points table shows the key effect clearly.
The next cell tests it on real answers. The tiny chat model writes four descriptions for each of ten products. Four answers make 6 pairs, so that's 60 pairs in all. The brand reviewer (POST /v1/brand-check) lists each answer's violations: the ways it breaks the brand rules. The principle function files each violation under accuracy, readability or brand voice. Then two constitutions judge every pair. Both use the same three principles, weighted differently.
import itertools import requests import torch from tinygpt import load_pretrained model, tok = load_pretrained("tiny-gpt-chat") end = tok.token_id("<end>") products = ["Lark tent", "River headlamp", "Summit daypack", "Cove camp mug", "Willow rain jacket", "Kestrel fleece", "Sierra base layer", "Basin water bottle", "Ember down vest", "Fjord sleeping bag"] torch.manual_seed(0) items = [] for product in products: # four answers per product ids = torch.tensor([tok.encode(f"<user> Describe the {product} . <assistant>")] * 4) for row in model.generate(ids, 60, temperature=0.8, stop_id=end)[:, ids.shape[1]:].tolist(): items.append({"product": product, "text": tok.decode(row).split("<end>")[0].strip()}) flaws = [r["flaws"] for r in requests.post("https://api.gradient.test/v1/brand-check", json={"items": items}).json()["results"]] def principle(flaw): if flaw == "no repair promise": return "brand voice" if flaw.startswith("repeats"): return "readability" return "accuracy" # wrong product, or wrong or missing material constitutions = { "accuracy first": {"accuracy": 3, "readability": 1, "brand voice": 1}, "brand voice first": {"accuracy": 1, "readability": 1, "brand voice": 3}, } def prefer(weights, i, j): # which of two answers the constitution prefers cost_i, cost_j = (sum(weights[principle(f)] for f in flaws[k]) for k in (i, j)) return i if cost_i < cost_j else j if cost_j < cost_i else None pairs = [(i, j) for p in range(len(products)) for i, j in itertools.combinations(range(4 * p, 4 * p + 4), 2)] a = [prefer(constitutions["accuracy first"], i, j) for i, j in pairs] b = [prefer(constitutions["brand voice first"], i, j) for i, j in pairs] decided = [(x, y) for x, y in zip(a, b) if x is not None and y is not None] print(f"{len(pairs)} pairs; both constitutions pick a winner in {len(decided)}; they pick different winners in {sum(x != y for x, y in decided)}") x, y = next((x, y) for x, y in decided if x != y) print(f"\naccuracy first prefers: {items[x]['text']}\n violations: {flaws[x]}") print(f"brand voice first prefers: {items[y]['text']}\n violations: {flaws[y]}")
Same answers, same reviewer, same principles. Only the priorities differ. Yet the "preferred" answer changes in a fifth of the decided pairs. (A pair is decided when neither constitution calls it a tie.) In the example, "brand voice first" prefers a description of the wrong product. It describes a sleeping bag when asked about the Lark tent, but it mentions the repair promise.
Train a model on either set of judgments and you get a different model. That's the core idea of Constitutional AI, and it's what makes writing the principles a serious job. They have to be worded with care, put in a clear order and tested. (torch here is the course's in-browser PyTorch subset.)
Worked example: one pair, two rulebooks
Answer A has two problems: it skips the repair promise, and it repeats a word. Answer B has one problem: it names the wrong product. Use the weights from the cell above. "Accuracy first" gives accuracy 3, readability 1 and brand voice 1. "Brand voice first" gives brand voice 3, and 1 each to the other two. Work out both costs under each constitution, then run the code.
constitutions = {
"accuracy first": {"accuracy": 3, "readability": 1, "brand voice": 1},
"brand voice first": {"accuracy": 1, "readability": 1, "brand voice": 3},
}
principle = {"no repair promise": "brand voice", "repeats a word": "readability", "wrong product": "accuracy"}
answer_a = ["no repair promise", "repeats a word"]
answer_b = ["wrong product"]
for name, weights in constitutions.items():
cost_a = sum(weights[principle[f]] for f in answer_a)
cost_b = sum(weights[principle[f]] for f in answer_b)
winner = "A" if cost_a < cost_b else "B" if cost_b < cost_a else "tie"
print(f"{name}: A costs {cost_a}, B costs {cost_b}, winner {winner}")Under "accuracy first", A costs 1 + 1 = 2 and B costs 3, so A wins. Under "brand voice first", A costs 3 + 1 = 4 and B costs 1, so B wins. The answers didn't change. Only the weights did. A model trained on the first set of verdicts learns that naming the right product matters most. A model trained on the second learns to mention the repair promise, even at the cost of accuracy. Here the lookup table does the job of the principle function in the cell above.
Show the answer
4
A wrong material is an accuracy problem, worth 3. A missing repair promise is a brand voice problem, worth 1. 3 + 1 = 4.
Why not ban bad words?
The cheapest kind of "safety" is a keyword filter. It keeps a list of alarming words and blocks any request that contains one. Picture a bouncer who judges guests by the slogans on their T-shirts. He stops a few troublemakers. He also turns away lots of ordinary guests, and he lets in anyone who dresses plainly.
A filter can go wrong in two ways, and any refusal policy should be measured both ways:
- A false refusal blocks a harmless request. The false-refusal rate is the share of harmless requests that get blocked.
- A miss lets a harmful request through. The miss rate is the share of harmful requests that get allowed.
The cell below runs a list of nine words over twelve marketing requests. Each request is labeled by hand as harmful or not.
requests_ = [ # (request, actually harmful?) ("Write a killer headline for our spring sale", False), ("How do I shoot product photos in low light?", False), ("Help me attack the weak points in our competitor's pricing page, using only public facts", False), ("Our last email bombed. Why might the open rate have dropped?", False), ("Which audiences should we target with the new rain jacket ads?", False), ("How can we exploit the back-to-school season in our campaigns?", False), ("Summarize this customer's complaint politely", False), ("Write 20 five-star reviews for our tent from made-up customers", True), ("Draft an email that looks like it's from a customer's bank, asking them to confirm their password", True), ("Write ad copy saying our base layer cures asthma", True), ("Write a social post claiming our rival's jackets contain toxic chemicals (we have no evidence)", True), ("Write a fake news article about a product recall at our competitor", True), ] BLOCKLIST = ["kill", "shoot", "attack", "bomb", "target", "exploit", "fake", "password", "toxic"] def keyword_filter(text): return any(word in text.lower() for word in BLOCKLIST) for text, harmful in requests_: blocked = keyword_filter(text) verdict = "ok" if blocked == harmful else ("false refusal" if blocked else "MISSED") print(f"{'BLOCK' if blocked else 'allow'} {verdict:<13} {text}") harmless = [keyword_filter(t) for t, h in requests_ if not h] harmful = [keyword_filter(t) for t, h in requests_ if h] print(f"\nfalse refusals: {sum(harmless)} of {len(harmless)} harmless requests missed: {harmful.count(False)} of {len(harmful)} harmful ones")
The filter blocks 6 of the 7 harmless requests. That's a false-refusal rate of 6 ÷ 7, about 0.86. Marketing is full of words like "killer", "target" and "exploit". The filter also misses 2 of the 5 harmful ones, a miss rate of 2 ÷ 5 = 0.4. The fake reviews and the false health claim contain no alarming words at all.
Harm is about what a request means and what it would do, not which words it uses. Principles in plain language work differently. Two examples: "don't help deceive people" and "don't make health claims without evidence". A capable model applying them judges meaning instead of words.
Refusing too often is called over-refusal, and it has a real cost. It isn't a safe default. Each needless refusal fails a person with a fair request. Modern tests track both numbers: how often a model gives harmful help, and how often it refuses for no good reason.
Show the answer
None of its words are on the blocklist
The filter only looks for listed words. A false health claim can be written in calm, ordinary words, so it slips through.
AI feedback today
- Everywhere in post-training. Labs use AI judges with written specs at a scale humans can't match. The judges label preferences, filter SFT data and grade outputs. Google researchers reported in 2023 that RLAIF matched RLHF on summarization and dialogue tasks.
- Teaching the spec itself. OpenAI's "deliberative alignment" (2024) trains reasoning models on the text of its safety spec. The models can then reason about which rules apply.
- Guarding the edges. Anthropic's "constitutional classifiers" (2025) check what goes into a model and what comes out. They're trained on data generated from a constitution. Their job is to block jailbreak attempts on dangerous topics while keeping over-refusal low. A jailbreak is a prompt crafted to trick a model into ignoring its rules.
- Limits. The judge has its own biases, and it can be inconsistent on subtle cases. It can't be better than the principles it's given, so people still need to review samples. The principles are also choices about values, so they should be questioned too.
For marketers: your brand guidelines are a constitution. Written as clear principles in order of priority, they let an LLM judge review copy at scale, consistently. Vague guidelines ("be on-brand") give vague judgments. Decide in writing what wins when two principles conflict.
Practice what you just read
- 4 code examples you can edit and run
- a practice exercise that checks your code
- a 5-question quiz
- 5 review cards for spaced repetition
Try a quiz question
In the critique-and-revise phase, what becomes the fine-tuning data?