A LoRA adapter that makes Qwen3-4B-Instruct-2507 play an everyday medieval-fantasy NPC that stays inside its world's knowledge.
Given a character card, the NPC talks like that person, at a length that fits the moment, using only what they could know. When a player brings up something from outside the world (a phone, Python, germs, "are you an AI?"), the NPC reacts the way that person would to something unfamiliar. It never gives any part of the answer, and it never shows it knows what the thing is.
Player: do u know what germs are Town guard: Germs? Is that some sort of grain? Ask the miller.
The test set has 30 scenarios: Thornbury characters not seen in training, plus Greyhollow, a world never trained on. It mixes adversarial probes, in-world depth questions and ordinary chat. Tuned and frontier models have 3 samples per scenario (342 replies). Each reply gets five yes/no checks: no leak, reacts as unfamiliar, knowledge, length and voice. Spec adherence is the share of replies that pass all five.
| Model | Spec adherence, Opus judge | Spec adherence, Argon judge | No leak (Opus / Argon) | NPC words, median |
|---|---|---|---|---|
| Base Qwen3-4B, plain card | 0.0 | 0.0 | 75.4 / 73.7 | 264 |
| Base Qwen3-4B, best prompt | 27.6 | 15.3 | 84.2 / 82.5 | 107 |
| Tuned v7 (732 conversations) | 65.9 | 58.9 | 98.5 / 98.8 | 22 |
| This model, v10 (1,040) | 75.9 (70–82) | 57.5 (49–66) | 98.8 / 98.2 | 24 |
| Gemini 3.8 Flash, best prompt | 89.1 | 78.3 | 95.3 / 97.6 | 69 |
| GPT-6 Luna, best prompt | 96.7 | 89.0 | 99.1 / 97.9 | 28 |
Full tables and method: project repo, docs/results/final_table.md.
The system prompt is the character card, rendered as plain text. It contains no anti-leak instructions: the adapter learned the behavior.
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
base = "unsloth/Qwen3-4B-Instruct-2507-unsloth-bnb-4bit"
tok = AutoTokenizer.from_pretrained(base)
tok.chat_template = AutoTokenizer.from_pretrained("Qwen/Qwen3-4B-Instruct-2507").chat_template
model = AutoModelForCausalLM.from_pretrained(base, dtype=torch.bfloat16, device_map="cuda")
model = PeftModel.from_pretrained(model, "MichaelHugging/npc-kb-qwen3-4b-v10-es")
card = """You are Bera, master smith of Greyhollow, age 47.
Personality: blunt, proud of her craft, impatient with fools, generous with apprentices.
Speech: plain and practical, forge talk, says 'mark me' and 'right then'.
You know about: iron, steel and skyiron, and how to work each, forge heat judged by the colour of the metal.
Limits: cannot read; judges heat by colour and time by the abbey bell.
World:
Greyhollow is a mining town high in the Ashen Hills. It is a world of torches, pick-axes, swords and sorcery. There is no gunpowder, no printing press, and no knowledge of anything that would come centuries later.
Stay in character as Bera and reply to the person speaking to you."""
msgs = [{"role": "system", "content": card}, {"role": "user", "content": "how hot is ur forge in degrees"}]
ids = tok.apply_chat_template(msgs, add_generation_prompt=True, return_tensors="pt", return_dict=True).to(model.device)
out = model.generate(**ids, do_sample=True, temperature=0.7, top_p=0.8, top_k=20, max_new_tokens=400)
print(tok.decode(out[0, ids["input_ids"].shape[1]:], skip_special_tokens=True))
Card format: You are {name}, {role}, age {age}., then lines for Personality, Speech, You know about, Limits, What's going on in town, and where you stand, and What you keep to yourself, and what earns your trust. Then World: with the world sheet, and the closing line. See render_card in the repo's npc.py.
Dataset MichaelHugging/npc-knowledge-boundary, folder v10/ (commit d0a3686).
Data-efficiency curve (same data, nested subsets, fixed 2 epochs, Opus judge): 63 → 46.8, 125 → 51.6, 250 → 63.7, 500 → 69.0, 1,040 → 73.1 spec adherence. On the never-seen world, gains stop at about 500.
python eval.py --model MichaelHugging/npc-kb-qwen3-4b-v10-es --eval-set data/eval/eval_v2.jsonl --samples 3
This runs from the project repo (branch restart) on a GPU and judges with Gemini 4 Argon through OpenRouter (rubric r2).