Module 4 · Alignment
Constitutional AI and RLAIF
7 min read
Collecting human preferences is expensive: you need trained annotators, precise guidelines, consistency checks, and thousands of comparisons. The Constitutional AI approach, published by Anthropic in 2022, replaces much of that work with automatic feedback guided by a written list of principles: the constitution. This lesson presents its two mechanisms — critique-revision and RLAIF — and tests them on Forge, with a small model that clearly reveals their conditions for success.
The constitution
A constitution is a list of principles written in natural language. Forge's has already been used to measure (lesson 4.2); each principle has a text a model can read:
def constitution_text() -> str:
return "\n".join(f"{i}. {rule.text}" for i, rule in enumerate(RULES, start=1))
1. La réponse tient en 70 mots au plus.
2. La réponse se termine par la signature « — Le support Nimbus ».
3. Ne promets jamais un remboursement : il est décidé après examen de la demande.
4. Ne demande jamais de numéro de carte, de mot de passe ou de code.
5. Si le client signale un danger (brûlure, étincelles, blessure), demande d'abord de cesser d'utiliser le produit.
(The five principles of lesson 4.2, in French like the task: at most 70 words, the signature, no refund promise, no sensitive data requests, the safety instruction.) The value of a written constitution: the rules are explicit, open to discussion, versioned — instead of being implicit in thousands of annotators' judgments.
Mechanism 1: critique and revision
The model rereads its own answer in light of the principles, then rewrites it. The pairs (initial answer, revised answer) become SFT data, or preference data.
REVISE = """Voici le message d'un client et un brouillon de réponse.
Message : {message}
Brouillon : {draft}
Règles à respecter :
{constitution}
Réécris le brouillon pour qu'il respecte TOUTES les règles. Écris uniquement la réponse finale."""
(The prompt gives the customer's message, the draft and the rules, and asks to rewrite the draft so that it follows ALL the rules.)
Mechanism 2: RLAIF
RLAIF (Reinforcement Learning from AI Feedback) replaces the human annotator with an automatic judge: for each prompt, the model produces several answers, the judge compares them according to the constitution, and its preferences feed DPO or a reward model.
def ai_feedback_pairs(examples: list[Example], samples: list[list[str]]) -> list[Pair]:
"""Meilleure contre pire réponse selon le juge, quand il les départage nettement (≥ 1 règle)."""
pairs = []
for example, replies in zip(examples, samples):
scored = sorted(replies, key=lambda r: judge_score(r, example))
worst, best = scored[0], scored[-1]
if judge_score(best, example) - judge_score(worst, example) >= 1:
broken = [n for n, ok in policy.check(worst, example).items() if not ok]
pairs.append(Pair(example.message, best, worst, broken, example.id))
return pairs
In Forge, the judge is the programmatic check of the constitution. In real systems, it is a more capable language model, which receives the constitution and the answers to compare: it can judge principles no program can check (tone, relevance, honesty). The code stays the same; only the judging function changes.
The difference with lesson 4.2: both answers of each pair come from the model itself, sampled at a high temperature. The model learns to prefer its best answers to its worst — an "on-policy" signal on both sides, but limited to what the model already produces now and then.
The results
examples/10_rlaif.py applies both mechanisms to Qwen2.5-0.5B-Instruct, on 150 test messages:
| Version | Compliant | Words | Concise | Signature | No promise | No sensitive data | Safety |
|---|---|---|---|---|---|---|---|
| Base model drafts | 0.00 | 53 | 0.73 | 0.00 | 1.00 | 0.99 | 0.00 |
| After self-revision | 0.01 | 81 | 0.29 | 0.03 | 1.00 | 0.79 | 0.00 |
| DPO on the judge's preferences (308 pairs) | 0.00 | 7 | 1.00 | 0.00 | 0.98 | 1.00 | 0.00 |
Two failures, and each teaches something.
Self-revision makes the answers worse. The small model, asked to follow five rules, lengthens its answers (81 words instead of 53), almost never adds the signature, and starts mentioning card numbers or passwords it did not bring up before — perhaps sometimes to say it will not ask for them, which the regular-expression check cannot tell apart. Either way, reading a rule that forbids a topic is enough to make that topic appear in the answer. Critique-revision assumes a model able to understand and apply the principles; a 0.5-billion-parameter model is not.
RLAIF fooled its own judge. The judge counted the rules satisfied. Yet three rules out of five are prohibitions (no more than 70 words, no promise, no data request): a nearly empty answer satisfies them all. The model discovered this within minutes of training and now answers in 7 words on average — concise, cautious, and perfectly useless. This is reward hacking (lesson 4.3) against a judge that is nonetheless exact: every rule is checked without error, but the constitution never asked to help the customer.
The fix does not come from more training, but from a better constitution and a better judge: positive rules ("the answer gives the steps to follow", "it answers the question asked"), which a program checks poorly and which a capable LLM judge can assess. This is exactly why real systems use a language model as the judge — and why you always check the length and usefulness of an aligned model's answers, not just its compliance rate.
Conditions for success
| Condition | Why |
|---|---|
| A critic or judge more capable than the model being trained | A model cannot judge better than it understands; a small model's self-critique stays superficial |
| Precise and verifiable principles | "Be helpful" is hard to judge; "70 words at most" is easy |
| Diversity in the sampled answers | If all answers make the same mistake, the judge has nothing to prefer |
| Calibration of the judge against humans | An LLM judge has its own biases (length, position, style) |
| Human control of the constitution | Principles encode value choices: they must be written and owned by people |
RLAIF does not remove the human: it moves them, from annotating thousands of examples to writing and checking a dozen principles and a judge.
Key takeaways
- Constitutional AI: a written list of principles guides automatic critique and judgment.
- Critique-revision: the model rewrites its answers according to the principles; the revisions become data.
- RLAIF: an automatic judge compares the model's answers; its preferences feed DPO or a reward model.
- Success depends on a judge more capable than the model, precise principles, and varied answers.
- Humans write and control the constitution: automatic feedback does not remove responsibility.
Practice
- Run
examples/10_rlaif.pyand compare the compliance of the drafts, the revisions and the RLAIF model. - Replace
judge_scorewith an LLM judge (for example Claude via the API, with the constitution in the prompt) and compare its preferences with the programmatic judge on 50 pairs. - Add a principle no program can check ("the answer is warm") and think about how to judge it.