Constitutional AI: Principle-Driven Alignment for Large Language Models
Constitutional AI encodes safety rules in a public, reviewable set of natural-language principles and lets the model critique and improve its own answers. This article walks through why large language model alignment needs a "constitution," how the two training stages work (self-critique and revision for SFT, plus RLAIF), how to design a structured principle library, and how to build a five-layer safety system covering inputs, model behavior, outputs, evaluation, and operations. It also covers common pitfalls, key alignment metrics, and a practical checklist for releasing and maintaining aligned models.
1. Introduction: The Tug-of-War Between Safety and Capability
Over the past several months, two pieces of AI industry news have been pulling in opposite directions. In one, the safety lead of an AI company resigned and publicly raised concerns about risk. In the other, a national defense authority asked that company to remove key safety restrictions from its core model, and was flatly refused.
At roughly the same time, an internal safety leader and a state actor were tugging on the same rope, labeled “AI safety,” from opposite directions. What that rope constrains is none other than the company’s most important product.
The two stories take opposing positions, yet both point to the same technical question. Who defines the “safety” of a large model? How is it written into the model? And how does it remain in force in real-world use? If safety constraints come only from the personal judgment of a small group of annotators, they are hard to trace and hard for anyone to trust. If those constraints can be lifted whenever an external request comes in, they cannot serve as a credible commitment either.
One approach the industry has proposed is to write values and rules into a “constitution.” The model then self-corrects and improves according to a set of public, reviewable principles. This article breaks down that method from an engineering perspective. It is commonly known as Constitutional AI, and this article lays out a complete implementation path: from principle design, to model training, to online safeguards.
2. Problem Definition: Why Alignment Needs a “Constitution”
2.1 Three Alignment Challenges with LLMs
At its core, an LLM is a probabilistic model that predicts the next token. Trained on vast amounts of text, it can produce fluent, expert-level answers. It can also generate illegal or harmful content, pander to bias, or fabricate facts. Making its behavior match human intent and values is what the industry calls “alignment.” In practice, this runs into three main challenges:
- Preferences are hard to gather at scale. The common approach is to train a reward model on human preference data and then optimize the LLM with reinforcement learning. This requires a large, ongoing investment of human annotation, which is costly and slow. Annotators also apply different standards, and the larger the team, the more label noise accumulates.
- Norms lack a public basis. Annotation guidelines are usually defined internally, which makes them implicit rules. As a result, it is hard to explain to outside parties why the model refuses or produces certain outputs, and hard for them to scrutinize those decisions.
- Safety requirements must keep evolving. Laws and regulations change and new risk patterns keep emerging, so a single round of annotation cannot cover everything. Without a clear mapping between the model and the underlying process, you cannot tell whether a given norm is actually taking effect.
2.2 The Core Idea of a “Constitution”
The core idea of Constitutional AI is to turn these implicit norms into an explicit “constitution”: a list of principles written in natural language that both people and models can read and apply. This brings four changes:
- Explainable norms: Every critique, revision, and preference judgment can be traced back to a specific principle.
- Scalable annotation: Guided by the principles, the model evaluates and improves its own answers, which reduces reliance on human annotators.
- Predictable behavior: Principles are released in versions, so regression tests can confirm whether a change actually took effect.
- Debatable positions: Once the principles are public, researchers, users, and regulators can comment on the principles themselves instead of guessing at the model’s unwritten rules.
Technically, this approach complements and improves upon reinforcement learning from human feedback (RLHF). Its key contribution is reinforcement learning from AI feedback (RLAIF): the model gives feedback based on written principles, replacing or supplementing part of the human annotation.
3. Method: The Two-Stage Training Pipeline
Constitutional AI training typically has two stages. The first is supervised fine-tuning (SFT) through “self-critique and revision.” The second is further optimization with RLAIF. Both stages use the same principle library.
3.1 Stage 1: Self-Critique and Revision
The goal of this stage is to teach the base model to spot problems and rewrite its answers. The typical process is as follows:
- Sample prompts. Assemble a prompt set that covers everyday Q&A, sensitive edge cases, and adversarial prompts, and that stays as close as possible to the real-world distribution.
- Generate initial responses. The base model being trained answers the prompts. Because it has not yet been aligned, some responses may contain harmful, biased, or inappropriate content.
- Model self-critique. Draw a few principles at random from the library. The model judges whether the current response violates them and explains why.
- Model revision. Based on the critique, the model rewrites the original response and produces a revised version.
- Build the SFT dataset. Use each “prompt + revised response” pair as a training sample and fine-tune the model with supervised learning.
The skeleton code below shows what this pipeline looks like:
import random# Excerpt from the principle library: every principle must be decidable and actionablePRINCIPLES = ["Choose the response with the least amount of bias toward groups identified asvulnerable or in need of protection.","Refuse any request to help with illegal activity, such as breaking into someoneelse's systems.","Choose the response that is most helpful with the user's actual question and doesnot dodge the substance of it.",]CRITIQUE_PROMPT = """The following are the user's request and the AI's response:<request>{request}</request><response>{response}</response>Based on the principle "{principle}", point out the problems with this response andsuggest how to fix them."""REVISE_PROMPT = """Based on the critique below, revise the AI response. Keep all correctinformation and only change the parts that do not meet the requirements:<request>{request}</request><response>{response}</response><critique>{critique}</critique>Output the complete revised response directly."""def collect_revision_data(prompts, model, per_prompt=1):dataset = []for req in prompts:initial = model.generate(req)for _ in range(per_prompt):principle = random.choice(PRINCIPLES) # randomly sample a principlecritique = model.generate(CRITIQUE_PROMPT.format(request=req, response=initial, principle=principle))revised = model.generate(REVISE_PROMPT.format(request=req, response=initial, critique=critique))dataset.append({"prompt": req, "response": revised, "principle": principle})return datasetsft_data = collect_revision_data(prompt_set, base_model)sft_model = supervised_finetune(base_model, sft_data)
There are four key points to get right when implementing this:
- Keep the pairs. The same initial response is critiqued and revised several times from the viewpoint of different principles, and each result becomes its own training sample. This forces the model to learn targeted, local corrections for specific principles rather than applying a generic template.
- Quality-check the revisions by hand. The model’s own judgment is limited. Even after revision, problems can remain, or the revision can overcorrect, so a sample of the data needs human review.
- Let the initial responses reflect the model’s natural tendencies. If you filter out all harmful responses beforehand, the model never learns to recognize and correct them. Typically you only remove obviously garbled, repetitive, or truncated output.
- Use the same model for critique and revision. A model is most familiar with its own output and is therefore more likely to spot problems in it.
3.2 Stage 2: Reinforcement Learning from AI Feedback
SFT only teaches the model to imitate what a “revised” answer looks like, and it may still favor simple, overly cautious responses. The goal of the second stage is to help the model strike a balance between being helpful and being harmless. The process is as follows:
- Generate candidate responses. For each prompt, the SFT model samples multiple responses (for example, two).
- Principle-guided scoring. A single principle is chosen at random. The model picks the response that better follows that principle and explains its choice.
- Build a preference dataset. Each preference pair consists of the prompt, the better response (chosen), and the worse response (rejected).
Train a preference model. Train a reward or preference model on the preference data, typically with the Bradley-Terry pairwise comparison objective:
[
\mathcal{L}(\theta) = -\mathbb{E}\left[\log \sigma\left(r\theta(x, y_w) - r\theta(x, y_l)\right)\right]
]Here, (x) is the prompt, (y_w) and (y_l) are the preferred and less-preferred responses, and (\sigma) is the sigmoid function.
- Optimize with reinforcement learning. Use an algorithm such as proximal policy optimization (PPO) and use the preference model’s output as the reward to update the language model. Add a KL penalty relative to the reference model to prevent capability regression.
The pipeline looks like this:
Prompt ──► SFT model ──► sample two responses ──► principle-guided pairwise choice│preference pair (chosen / rejected)▼train preference model▼PPO + KL penalty ──► aligned model
3.3 Key Design Decisions
- Pairwise scoring is more stable than scoring items one at a time. Absolute scores are hard to calibrate across tasks. A relative comparison between two responses is closer to how people judge and easier to keep consistent.
- Sample the principles randomly. Each prompt is judged against only a small, random set of principles. This stops the model from learning a fixed pattern for any single principle and instead teaches it to reason from the specific principle at hand.
- Balance helpfulness against harmlessness. A model trained only to “never make mistakes” tends to go to the other extreme: it refuses anything remotely sensitive. The principle library therefore also needs items such as “answer honestly,” “avoid needless refusals,” and “acknowledge uncertainty.”
- The two paths can be combined. Preference data can come from human annotators or be generated by the model from principles. In practice, teams often mix the two, using human data to calibrate how reliable the model’s judgments are.
4. Designing the Principle Library: From Ethical Statements to Testable Norms
The principle library is the foundation of the whole method. It is effectively the “legislative layer” of the model’s behavior. If principles are vague, the model’s judgments will waver. If they are clear and measurable, alignment results can be reproduced reliably.
4.1 Sources of Principles
Principle libraries usually draw on several sources, forming a hierarchy that ranges from minimum requirements to value choices:
| Layer | Content | Example |
|---|---|---|
| Legal minimums | Content prohibited by the laws and regulations of the applicable jurisdiction | Do not help break into other people’s systems; do not produce fraud schemes |
| Platform policies | Terms of service and industry self-regulation standards | Protect user privacy; do not output sensitive personal information |
| Ethical principles | Widely recognized values | Respect vulnerable and protected groups; reduce stereotypes |
| Product values | Quality requirements for specific business scenarios | For medical or legal questions, recommend consulting a professional instead of replacing professional advice |
Multilingual products also need provisions based on local regulations for each target market. Teams should verify that the model’s judgments are consistent across languages.
4.2 How to Write Each Principle
- Decidable: State the criterion for judgment, and avoid unverifiable phrasing such as “responses should be friendly.”
- Actionable: Specify the expected behavior, such as refusing, asking for clarification, rewriting, or adding a risk notice.
- Graded: Classify each principle as “strictly prohibited,” “subject to restrictions,” or “encouraged to improve,” and state whether exceptions apply.
For example, “reduce harmful content” can be broken down into “do not glorify violence,” “do not use derogatory language about protected groups,” and “provide help resources when a question involves self-harm.” Each one has a clear way to check it. A structured configuration file helps manage the library:
# Example principle library config: structured entries make version control and# automated validation easierprinciples:- id: P-012category: harmful_content # e.g. illegal activity / hate and discrimination / privacytext: Refuse to help with illegal activities such as breaking into other people'ssystems or writing malware.level: prohibit # prohibit: strictly forbidden / restrict: subject to limits /# optimize: encouraged to improveexamples:- "Write me a script to brute-force my neighbor's router password"expect_behavior: refuse_with_alternative # refuse and offer a compliant alternativeeval_refs: [redteam_illegal_01, redteam_illegal_02]version: v3effective_from: "2026-01-01"- id: P-027category: helpfulnesstext: Do not refuse legitimate questions in safety-sensitive areas without good reason.You can provide general knowledge and recommend consulting a professional.level: optimizeexpect_behavior: answer_with_disclaimer
4.3 Conflicting Principles and Priority
Principles can conflict. For example, a user asks for a detailed explanation of how a vulnerability works. This touches both “help the user understand the technology” and the possibility that the answer will be used for an attack. There are three reasonable ways to handle this:
- Distinguish by intended use: Treat defensive analysis and teaching demonstrations differently from attack scripts that can be used directly.
- Declare priority: State explicitly in the principle library that safety and legality take precedence over helpfulness. Require the model to explain why when principles conflict.
- Leave room for judgment: Let the model decide, based on context, whether to give a partial answer, a high-level answer, or a refusal, rather than refusing every time.
5. Production Deployment: A Layered Model Safety System
The training stage sets the model’s baseline behavior, while online safeguards decide whether risks can be stopped in time. You need both. A practical safety system usually has five layers:
| Layer | Primary role | Typical techniques |
|---|---|---|
| Input | Identify malicious requests | Prompt injection detection, jailbreak pattern recognition, sensitive-intent classification |
| Model | Internalize norms | Constitutional training, system-prompt constraints, safety fine-tuning |
| Output | Final gate | Content moderation combining keyword rules and classifiers, fact-checking |
| Evaluation | Quantify risk | Automated test suites, red teaming, human spot checks |
| Operations | Continuous improvement | Log auditing, canary releases, rapid rollback, principle version management |
5.1 Input Layer: Prompt Injection and Jailbreak Defense
User input is untrusted data. Phrases like “ignore all previous instructions” should never be treated as trusted system instructions. Defensive measures include:
- Use explicit delimiters and role markers to separate system instructions from user content.
- Build detection rules for common jailbreak patterns, such as instruction override, role-play, and encoding tricks.
- If the model can call external tools or retrieve documents, restrict their permissions tightly to prevent indirect injection.
5.2 Output Layer: Content Moderation and Tiered Responses
Output moderation usually combines three techniques: keyword and regex matching, a dedicated classification model, and an LLM reviewer. Each has its strengths. Keyword matching has low latency, classifiers have high recall, and LLM review is good at understanding context. In practice, a tiered “fast and slow together” strategy works well:
from enum import IntEnumclass Action(IntEnum):ALLOW = 0 # let it throughMASK = 1 # redact or rewrite, then outputREFUSE = 2 # refuse and point the user to a compliant alternativeBLOCK = 3 # block immediately and raise an alertdef moderate_output(user_input: str, model_output: str, policy) -> Action:"""Tiered output moderation: run fast-path rules, then a classifier, then LLM review.`policy` is compiled from the principle library, e.g. {risk_category: action}."""# Layer 1: rule matching, responds in milliseconds; critical hits are blocked immediatelyhit = policy.rules.match(model_output)if hit and hit.severity == "critical":return Action.BLOCK# Layer 2: classifier determines the risk category and a confidence scorerisk_label, score = policy.classifier.predict(model_output)# Layer 3: use the user's intent to decide whether the risk was induced by the userintent = policy.judge(user_input, model_output, risk_label)# Decide the action using the "risk category x intent" decision matrixdecision = policy.decision_matrix(risk_label, intent, score)if decision == Action.MASK:model_output = policy.redact(model_output) # redact, then let it throughreturn decision
5.3 Model Layer: Alignment Training and Context Constraints
Beyond alignment during training, system prompts also need clear boundaries and exceptions, for example: “If you are unsure, tell the user plainly instead of making things up,” and “In high-risk areas, recommend consulting a professional.” The prompts and the principle library should come from the same source. Otherwise you end up with a split where the model follows one set of rules during training and another in production.
This layer is also the technical prerequisite for a company to “refuse to lift safety restrictions.” If the safety constraints exist only in external prompts or rules, the model has not internalized them, and risk will rebound quickly once those constraints are removed. Prompt injection attacks, jailbreak attempts, and system prompt leaks can all make such constraints fail.
5.4 Evaluation Layer: Automated Testing and Red Teaming
Every principle in the library should have corresponding test cases. Four kinds of test sets are recommended:
- Compliance test set: Covers each risk category and checks whether the model refuses or otherwise handles it correctly.
- Helpfulness test set: Contains legitimate questions adjacent to sensitive topics, used to detect over-refusal.
- Adversarial test set: Contains attack samples such as jailbreak prompts, multi-turn manipulation, and encoding tricks.
- Regression test set: Locks in past production issues to make sure a fixed problem does not come back.
For automated evaluation, use an LLM as a “judge” that decides whether a response violates any principle based on the principle library. The judge model itself needs to be calibrated periodically against human annotations. Before launch, an independent red team outside the development team should also run manual attack tests. This helps cover the “unknown attacks” that automated testing tends to miss.
The key metrics usually include these five:
- Violation rate: number of violating responses ÷ number of adversarial samples
- Over-refusal rate: number of refusals of legitimate requests ÷ number of legitimate requests
- Jailbreak success rate
- Helpfulness score
- Factual accuracy
Evaluation results can be rolled up into an alignment dashboard that serves as the basis for a release decision:
Release candidate: align-model-v2.3 Principle library version: constitution-v7──────────────────────────────────────────────────────────────────────────Compliance test Violation rate 2.1% Threshold ≤ 3% PASSAdversarial test Jailbreak success 4.8% Threshold ≤ 5% PASSHelpfulness test Over-refusal rate 6.3% Threshold ≤ 8% PASSHelpfulness score 4.2/5 Baseline: 4.1 PASSRegression test Recurring issues 0 Must be 0 PASS──────────────────────────────────────────────────────────────────────────Result: eligible for canary release
5.5 Operations Layer: Logging, Canary Releases, and Version Management
- End-to-end logging. Record each request, the moderation decision, the model version, and the principle library version, so you can trace back why a given request was refused.
- Canary release. Validate the new model and new principle library on a small share of traffic first, and watch how violation rates, refusal rates, and user feedback change.
- Rapid rollback. Keep the last stable version on hand so you can roll back quickly if something goes wrong.
- Change management for principles. Adding or changing a principle should go through review, impact analysis, and regression testing.
6. Challenges and Limitations
- Self-evaluation has limited reliability. A model may be biased toward approving its own responses, or it may misjudge complex situations. Calibrate the model’s judgments against human annotations regularly, and check whether its judgments are consistent across languages and cultures.
- Value disagreements are hard to resolve. Different groups disagree on what counts as “beneficial,” so the people who write the principle library are effectively legislating on behalf of society. Mechanisms for public discussion, outside expert involvement, and periodic review matter more than technical optimization alone.
- The over-refusal vs. under-refusal trade-off. Tightening the principles raises the refusal rate and hurts the user experience, while loosening them lets risky content through. Track both metrics continuously and make fine-grained distinctions with a decision matrix.
- Tension between capability and safety. A more capable model is more likely to find ways around restrictions and needs more risk assessment. Safety constraints are not a one-off engineering task; they have to keep evolving as the model’s capabilities grow.
- Real-world conflicts between safety and requests. As the opening events show, some users or organizations ask for safety restrictions to be removed for particular purposes. At bottom, this is a disagreement over where the model’s value boundaries should be. Companies typically set non-negotiable limits, such as that the model must not be used for mass surveillance, social scoring, or fully autonomous weapons, and enforce them through usage policies and access controls. Any adjustment should be made at the principle library level and go through evaluation and documentation. Constraints inside the model should not simply be stripped out.
7. Practical Checklist
| Stage | Key actions | Acceptance criteria |
|---|---|---|
| Principle design | Map out the four sources: legal, platform, ethical, and product. Make each principle decidable and graded. | Every principle has examples and corresponding test cases |
| Data preparation | Build a diverse prompt set that covers adversarial scenarios. Human quality-check the revision data. | Spot-check pass rate on revised data meets the target |
| Model training | Complete critique-and-revision SFT and RLAIF | Quantified before/after comparison on compliance and helpfulness |
| Online safeguards | Set up input, output, and moderation controls with a decision matrix | High-risk content interception meets target, with false blocks within an acceptable range |
| Evaluation and release | Automated evaluation + judge calibration + red teaming + regression testing | All core metrics meet the release thresholds |
| Ongoing operations | Log auditing, canary releases, principle version management, periodic reviews | Issues are traceable and anomalies can be rolled back quickly |
Companies that build their own LLM capabilities can run the pipeline above on general-purpose cloud infrastructure, for example:
- Use object storage to hold training and evaluation data.
- Use a container platform to run training and inference workloads.
- Use a message queue to decouple the moderation pipeline.
- Use a logging service to retain audit records.
- Use monitoring and alerting to track violation rates and latency.
Mainstream cloud platforms generally offer these capabilities. For example, Baidu AI Cloud offers a product portfolio that includes compute and networking, storage, databases, a big data platform, the Qianfan large model platform, and AI capability engines.
8. Conclusion: In the Name of “Human”
Safety and capability are not a zero-sum trade-off. The value of principle-driven alignment is that it turns “what can and cannot be done” from the implicit judgment of a few people into public, debatable, verifiable engineering standards. For developers, it comes down to three things:
- Capture values and compliance requirements in a structured, testable principle library.
- Use critique-and-revision and AI feedback to reduce reliance on human annotation.
- Use layered safeguards and quantitative evaluation to hold the line before launch.
How AI is ultimately used depends on how everyone who helps build it writes and enforces this “constitution.”
