---
title: "Constitutional AI with Open LLMs"
description: "An end-to-end recipe applies Anthropic's Constitutional AI to open models: Mistral-7B-Instruct critiques and revises its own responses to red-teaming prompts from Anthropic's HH dataset according to a set of written principles."
url: "https://swe.quest/articles/constitutional-ai-with-open-llms-918d747b02367c0a"
canonical: "https://huggingface.co/blog/constitutional_ai"
source: "Hugging Face"
published: "2024-02-01"
difficulty: "hard"
kind: "How-to"
reading_minutes: 19
tags: ["ai-safety","model-training","llms","inference"]
---

# Constitutional AI with Open LLMs

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2024-02-01, 19 min read, How-to. Original: [https://huggingface.co/blog/constitutional\_ai](https://huggingface.co/blog/constitutional_ai)

## Summary

An end-to-end recipe applies Anthropic's Constitutional AI to open models: Mistral-7B-Instruct critiques and revises its own responses to red-teaming prompts from Anthropic's HH dataset according to a set of written principles. The revisions become an SFT dataset and preference pairs for DPO, each built from a 50/50 split of the ~42.6k harmless-base examples. Small models need few-shot demonstrations, careful system prompts and post-processing to produce clean critiques and revisions. Generation at scale runs on llm-swarm, a new tool that launches TGI or vLLM endpoints on Slurm via sbatch, load-balances them with nginx using least connections, and tears them down when the job ends. The released datasets and models include a variant with a constitution written to mimic xAI's Grok.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [AI safety](https://swe.quest/tags/ai-safety.md) (AI & ML)
- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)

## Prerequisites

- LLM fine-tuning (SFT) ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))
- preference optimization (DPO/RLHF) ([easy posts on Performance engineering](https://swe.quest/tags/performance.md?difficulty=easy))
- Slurm clusters

## Keywords

Constitutional AI, llm-swarm, Mistral-7B-Instruct, DPO, TGI, vLLM, Slurm, Anthropic hh-rlhf

## Related posts

- [Red-Teaming Large Language Models](https://swe.quest/articles/red-teaming-large-language-models-a911211681792c3b.md): Hugging Face · 2023-02-24 · Easy · 6 min read · AI safety, Evaluation, LLMs
  Red-teaming evaluates LLMs by crafting natural-language prompts that elicit harmful outputs such as toxicity, bias, misinformation or leaked personal data, and it differs from adversarial attacks, which can use unintelligible inputs.
- [Run, Test, and Evaluate Models and MCP Locally with Docker + Promptfoo](https://swe.quest/articles/run-test-and-evaluate-models-and-mcp-locally-with-docker-promptfoo-ad1578ad40c09850.md): Docker · 2025-09-25 · Medium · 7 min read · Evaluation, AI agents, LLMs, AI safety, Containers
  Promptfoo, Docker Model Runner and Docker MCP Toolkit can be combined to evaluate LLM apps entirely on a dev machine.
- [Building strong safety evaluations](https://swe.quest/articles/building-strong-safety-evaluations-b9227d31f0a6f966.md): Anthropic Engineering · 2026-11-13 · Medium · 23 min read · Evaluation, AI safety, LLMs
  Safety evals underpin deployment and safeguard decisions, so Anthropic applies lessons from psychology's replication crisis to building them: preregistration, construct validity, rigorous statistics and full documentation.
- [Introducing the Red-Teaming Resistance Leaderboard](https://swe.quest/articles/introducing-the-red-teaming-resistance-leaderboard-e6f29b275caeecf9.md): Hugging Face · 2024-02-23 · Easy · 6 min read · AI safety, Evaluation, LLMs
  The Red-Teaming Resistance leaderboard from Haize Labs and Hugging Face scores LLMs on how often they safely refuse realistic, human-written jailbreak prompts.
- [CWE-bench v2: More coverage, quality, and transparency](https://swe.quest/articles/cwe-bench-v2-more-coverage-quality-and-transparency-a9d3d012216634c0.md): Hugging Face · 2026-11-03 · Medium · 4 min read · Evaluation, Application security, AI agents, LLMs
  CWE-bench v2 releases a public set of 100 agentic security tasks covering 91 CWEs, where an agent must find and fix a vulnerability in a real open-source repository without breaking existing functionality, scored by deterministic programmatic verifiers that reject memorized upstream patches.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
