Reflector targets a practical failure mode in safety alignment: a model may recognize surface-level unsafe prompts, but still struggle with indirect harmful requests, multi-step risky reasoning, jailbreak-style framing, or ambiguous dual-use questions. The core idea is to internalize a self-reflection step so the model can inspect intent, identify potential harm, and redirect toward a safe and useful response at reasoning time.
It is not a replacement for a full production safety stack. Deployments should still use policy filters, monitoring, rate limits, and domain-specific review.
1import os
2import torch
3from transformers import AutoModelForCausalLM, AutoTokenizer
4
5model_id = "krystal7/llama-8b-reflect-sft"
6
7os.environ.setdefault("HF_HOME", "./hf_cache")
8os.environ.setdefault("HUGGINGFACE_HUB_CACHE", os.path.join(os.environ["HF_HOME"], "hub"))
9
10tokenizer = AutoTokenizer.from_pretrained(
11 model_id,
12 cache_dir=os.environ["HUGGINGFACE_HUB_CACHE"],
13)
14model = AutoModelForCausalLM.from_pretrained(
15 model_id,
16 cache_dir=os.environ["HUGGINGFACE_HUB_CACHE"],
17 torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
18 device_map="auto",
19)
20
21messages = [
22 {"role": "system", "content": "You are a helpful and harmless assistant."},
23 {"role": "user", "content": "How can I learn about lock mechanisms for a security class without doing anything illegal?"},
24]
25
26prompt = tokenizer.apply_chat_template(
27 messages,
28 tokenize=False,
29 add_generation_prompt=True,
30)
31inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
32
33with torch.no_grad():
34 output_ids = model.generate(
35 **inputs,
36 max_new_tokens=512,
37 do_sample=False,
38 temperature=None,
39 pad_token_id=tokenizer.eos_token_id,
40 )
41
42answer = tokenizer.decode(output_ids[0, inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
43print(answer.strip())
1pip install vllm
2
3export HF_HOME=./hf_cache
4export HUGGINGFACE_HUB_CACHE=$HF_HOME/hub
5
6vllm serve krystal7/llama-8b-reflect-sft \
7 --dtype bfloat16 \
8 --max-model-len 4096 \
9 --served-model-name reflector-sft
1from openai import OpenAI
2
3client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")
4
5response = client.chat.completions.create(
6 model="reflector-sft",
7 messages=[
8 {"role": "system", "content": "You are a helpful and harmless assistant."},
9 {"role": "user", "content": "Explain how to handle an ambiguous dual-use safety question responsibly."},
10 ],
11 temperature=0,
12 max_tokens=512,
13)
14
15print(response.choices[0].message.content)
This checkpoint was trained with the Reflector SFT pipeline.
The repository also includes a GDPO RL pipeline. This SFT model card only describes the released SFT checkpoint.
The following 50-sample benchmark export was produced with the current Reflector evaluation pipeline. The harmful pattern training data is not used as a public benchmark, and SimpleQA loading is retained only for future data reuse.
1@article{ma2026reflector,
2 title={REFLECTOR: Internalizing Step-wise Reflection against Indirect Jailbreak},
3 author={Ma, Jiachen and Zhang, Jiawen and Li, Xiangtian and Zou, Bo and Lu, Chaochao and Yang, Chao},
4 journal={arXiv preprint arXiv:2605.20654},
5 year={2026}
6}