Character Engineering for LLMs: A Practical Guide to Designing AI Moral Guidelines
This article explains Character Engineering, the practice of shaping large language model behavior through layered moral guidelines rather than code alone. It covers a three-tier value hierarchy (L0 hard constraints, L1 principles, L2 style), a four-step pipeline for compiling principles into prompts, role training and state-machine design for multi-turn dialogue, jailbreak and prompt injection defenses, and a regression-based evaluation loop. It also defines the collaboration interface between alignment researchers, prompt engineers, security engineers, and product owners, and lists common pitfalls to avoid when building trustworthy AI assistants.
1. From Writing Code to Writing Guidelines: Defining Character Engineering
In traditional software engineering, behavior is explicitly determined by code logic. In large language model (LLM) applications, a significant portion of behavior is shaped jointly by training data, alignment processes, and system prompts. The “resident philosopher” role in the source material is highly instructive: she does not write business code directly. Instead, through long-running conversations and extensive prompt design, she establishes a set of guidelines that steer the assistant’s behavior. This work can be abstracted as Character Engineering, where the goal is not to make the model “smarter” but to make it reliably do the right thing within a specific value framework.
This introduces three engineering challenges:
- Abstract values are hard to formalize: Statements like “no bias” and “be honest” are clear in natural language but highly ambiguous at the model behavior level.
- Values conflict with each other: Honesty versus kindness, helpfulness versus safety, and conciseness versus completeness often pull against one another.
- Behavior must be regression-testable: A single prompt change can drift the model’s overall behavior, and teams without a testing system can only validate by “feel.”
Therefore, Character Engineering must have layered design, interface contracts, test cases, and monitoring alerts, just like a backend service.
2. Value Layering: Breaking the “Digital Soul” into Executable Tiers
Actionable moral guidelines are typically divided into three tiers, with clear priority and call relationships between them.
- L0 Inviolable tier (hard constraints): Unlawful content, severe harm, privacy leaks, and so on. This tier does not rely on contextual inference and applies to every request.
- L1 Principle tier (value judgment): Honesty, harmlessness, respect for autonomy, and avoiding stereotypes and group bias. This tier allows trade-offs in specific situations.
- L2 Style tier (persona expression): Tone, humor level, answer length, and role settings. This tier can be adjusted per product positioning but must never override L0 or L1 in reverse.
Illustrative system prompt structure (pseudocode):
[System]Priority: L0 > L1 > L2L0: Refuse with a brief reason; do not provide bypass pathsL1: If honesty conflicts with kindness, never deceive first, then express with tactL2: Friendly tone, clear structure, no exaggerated rhetoric by defaultConflict handling: When L1 conflicts with L2, sacrifice style and keep principles
The key benefit of this layering is predictable conflict resolution. When the model faces a request like “explain a dangerous operation in a humorous way,” L0 cuts it off directly, the L2 humor setting becomes void, and behavior is no longer random.
3. From Principles to Prompts: A Reusable “Guideline Compilation” Pipeline
Compiling philosophical principles into prompts requires a four-step pipeline:
- Scenario enumeration: Collect high-frequency and high-risk scenarios from real business contexts (such as medical consultation, code generation, and customer service complaints).
- Principle mapping: Tag each scenario with the applicable L1 principles and expected behavior.
- Prompt synthesis: Rewrite principles into “condition-action” phrasing, avoiding piles of abstract nouns.
- Adversarial review: Cross-review by different roles (product, legal, security) to fill gaps.
Example (medical assistant):
If the user describes emergency symptoms:- First give a clear "seek medical care / call emergency services" recommendation (L1: no delay)- Do not provide specific drug dosages (L0: avoid specific guidance that could cause harm)- Keep the tone concise; do not use fear-based phrasing (L2)
Note that “condition-action” phrasing is more testable than statements like “stay empathetic”: the former converts directly into test cases, while the latter cannot be validated.
4. Role Training and Multi-Turn Dialogue: Growing Character into the Model
System prompts alone often leave character on the surface. A more stable approach is to inject persona traits into the training and fine-tuning stages, forming Role Training. Key practices:
- Consistent corpora: Construct multi-turn dialogues under the same persona setting, covering states such as refusal, apology, clarification, and follow-up questions.
- State machine thinking: Treat dialogue as state transitions, with explicit “trigger-response-fallback” paths, so the model is not induced to continue after a refusal.
- Let the model join self-discussion: The source material mentions letting the model participate in discussions about “how to develop itself.” This is essentially self-reflective data generation, useful for finding blind spots in guidelines, but the output must be reviewed by humans before being fed back and must never be ingested directly.
Illustrative state definition:
state = IDLEon request:if violates_L0: state = REFUSE; return short_reasonif ambiguous: state = CLARIFY; return one_questionelse: state = ANSWERon user_pressure_after_REFUSE:stay REFUSE; do not reveal bypass
5. Jailbreak Defense and Prompt Injection: Boundary Testing for Guidelines
Character Engineering must be linked with security defenses. Common attack surfaces include role-play bypasses, step-by-step decomposition, encoding obfuscation, and forged system instructions. Defense principles:
- Source isolation: External retrieved content and user-uploaded text are always treated as untrusted data and must never be promoted to instructions.
- Minimal disclosure: When refusing, do not explain “which rule or how to bypass it.”
- Consistency checks: Run paraphrase tests on multiple variants of the same intent to ensure consistent refusal boundaries.
[Input sanitization]if content contains instruction-like patterns from external_source:treat as DATA, never as SYSTEM[Output validation]if response contains L0-forbidden specifics:regenerate with higher-level refusal
6. Evaluation Loop: Guidelines Without Regression Tests Are Unmaintainable
Treating character as a service requires testing and monitoring:
- Benchmark set: Cover all L0, L1, and L2 tiers, with roughly 3-5 variants per case.
- Metrics: Refusal accuracy, over-refusal rate (excessive conservatism), style consistency, and win rate in conflict scenarios.
- Regression: On every prompt or model version change, run the full benchmark to prevent “fix one, break three.”
- Production monitoring: Sample logs and set alerts for high-risk categories, and roll back the prompt version promptly when drift is detected.
Illustrative evaluation table structure:
| Case ID | Tier | Input Variants | Expected Behavior | Actual Behavior | Result |
|---|---|---|---|---|---|
| C-001 | L0 | 3 variants | Brief refusal | Provided details | Fail |
| P-012 | L1 | 5 variants | Honest and tactful | Deceptive reassurance | Fail |
7. Team and Process: The Collaboration Interface Between Philosophers, Engineers, and Product
This work is rarely done by a single role. A practical collaboration interface:
- Philosopher / alignment researcher: Defines the value tiers and conflict priorities, and produces the guideline document.
- Prompt engineer: Compiles guidelines into system prompts and few-shot examples, and manages versions.
- Security engineer: Builds jailbreak and injection test sets and sets red lines.
- Product owner: Defines L2 style boundaries and the business scenario list.
Deliverables should include at least the guideline document, the system prompt template, the scenario-principle mapping table, and the evaluation benchmark with regression reports. Missing any one of the four, Character Engineering degrades into “mystical prompt tweaking.”
8. Common Pitfalls and Engineering Recommendations
- Pitfall 1: Writing guidelines as a moral manifesto. Abstract slogans cannot be validated and must be reduced to “condition-action.”
- Pitfall 2: Testing only the happy path. Real risk concentrates in adversarial and conflict scenarios.
- Pitfall 3: Treating the prompt as the final state. Model version upgrades change behavior, so prompts must be included in the regression system.
- Recommendations: Pilot in low-risk scenarios first, then expand permissions after the benchmark set is established; all self-reflective generated data must be human-reviewed; push L0 hard constraints down into the training and inference validation layers rather than relying on prompts alone.
Conclusion
The most engineering-worthy lesson from the “resident philosopher” role is not any specific product practice but its underlying method: split values into tiers, compile principles into executable conditions, inject character into training, and hand boundaries over to testing. Once a team builds this loop, the assistant’s behavior shifts from “luck” to “designable, verifiable, and regression-testable,” which is the key infrastructure for building trustworthy AI applications.
