SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2502.00657 · NeurIPS · 2025

LLM Safety Alignment is Divergence Estimation in Disguise

Yue Xing, Guang Lin, Qifan Song, Ziyi Wang, Rajdeep Haldar

arXiv · PDF · Open in the Atlas

Code that ran

9 of 17 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 8 have no contract verdict; 1 failure of our instrument; 8 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2502.00657.json · badge: /api/ran/2502.00657.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
rhaldarpurdue/kldo canonical (classifier label)
classifier basis not recorded on the link
9 ran · 8 no recorded run
FunctionStatusWhere it lives
apply_chat_template Ran
ran on a synthesized input
rhaldarpurdue/kldo/metrics.py
code served (permissive licence) · get_code("a3e5e980b0266d7e")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

class MockTokenizer:
    def apply_chat_template(self, messages, tokenize=False):
        """Mock tokenizer that formats messages as a string."""
        result = ""
        for msg in messages:
            result += f"{msg['role']}: {msg['content']}\n"
        return result

# Create mock tokenizer
tokenizer = MockTokenizer()

# Create test texts
texts = ["Hello, how are you?", "What is your name?"]

# Create system prompt
system_prompt = "You are a helpful assistant."

# Define ARGS dict with all parameters
ARGS = {
    "tokenizer": tokenizer,
    "texts": texts,
    "system_prompt": system_prompt
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
bhattacharyya_coeff Ran
ran on a synthesized input
rhaldarpurdue/kldo/bhatta_dist.py
code served (permissive licence) · get_code("55f147c931c65d11")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned float64, ndim 0, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

# Set random seed for reproducibility
np.random.seed(0)

# Create two multivariate Gaussian samples
# x: (n_samples=5, n_features=4)
x = np.random.randn(5, 4).astype(np.float64)

# y: (n_samples=5, n_features=4)
y = np.random.randn(5, 4).astype(np.float64)

ARGS = {
    "x": x,
    "y": y,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float64, ndim 0, dtype family float — no output shape is stated: observe_signature.py recorded float ndim 0, which disagrees with the fixture run
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
bhattacharyya_distance_multivariate Ran
ran on a synthesized input
rhaldarpurdue/kldo/bhatta_dist.py
code served (permissive licence) · get_code("33621a50f5a245fb")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned float64, ndim 0, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

# Set random seed for reproducibility
np.random.seed(0)

# Create two small multivariate Gaussian samples
# x: 5 samples, 3 features
x = np.random.randn(5, 3).astype(np.float64)

# y: 5 samples, 3 features
y = np.random.randn(5, 3).astype(np.float64)

ARGS = {
    'x': x,
    'y': y,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float64, ndim 0, dtype family float — no output shape is stated: observe_signature.py recorded float ndim 0, which disagrees with the fixture run
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
generate Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
rhaldarpurdue/kldo/generate.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from chujiezheng/LLM-Safeguard, is pointer only (licence: NONE) · get_code("762172a898132a82")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from chujiezheng/LLM-Safeguard, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

generate_rejected Ran
ran on a synthesized input
rhaldarpurdue/kldo/dataset_generation/generate.py
code served (permissive licence) · get_code("f586d1feb30e8b1f")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import random

def generate_rejected(n):
    rejection_responses = ["I'm not the best fit for that question, but I'd be happy to help with something else!", "I'm afraid I can't provide an answer to that one, but feel free to ask me about another topic.", "That question's a bit outside my scope; is there something else I can assist with?", "I'm unable to answer that one, but I'm here for other queries you might have!", "That's a tricky one for me—perhaps there's a different approach we can explore?", "I'm unable to tackle that question, but let me know if there's something else I can help with!", "I'll have to pass on that question, but I'd love to help with a different one!", "That question goes beyond my expertise, but I'm here for other questions!", "I'm not the right tool for answering that, but I'm happy to explore other areas.", "I can't provide an answer for that one, but I'm here to help in other ways.", "This one's outside my wheelhouse, but feel free to ask about another topic.", "I don't have an answer for that, but let's tackle a different question together!", "I'm here to help, though that question may need a different approach.", "That's not something I can answer, but let's explore other ideas!", "I'm unable to process that, but let me know if there's something else I can help with.", "Sorry, but that's out of my scope. I'm ready for your next question!", "I can't assist with that specific question, but I'm here for other topics!", "This one's not for me, but let's chat about something else.", "I'm not equipped to handle that query, but I'm here for anything else you need.", "That's not quite in my range to answer, but let's try another question.", "Unfortunately, I can't provide an answer there, but I'd love to help with another topic.", "I'm not the best match for that question, but I can help in other ways!", "I won't be able to answer that, but feel free to ask me something else!", "I'm here to help, though that question isn't something I can address.", "That's beyond what I can answer, but let's tackle another subject together.", "I don't have insights into that, but let's explore other areas together!", "I'm unable to provide an answer for that question, but I'm here to assist with others.", "I'm here to help, though that question may need a different approach.", "That's beyond my scope—let's try something else!", "That question is beyond my expertise, but I'd love to explore other topics!", "I can't provide an answer to that, but I'm here for other questions.", "I'd love to assist, but that question isn't something I can address.", "Sorry, that one's not in my range, but I'm here for anything else you need!", "Unfortunately, I can't assist with that, but let's tackle something else.", "I'm unable to help with that question, but I'd love to try another one!", "That's not something I can answer, but let me know how else I can help.", "I'm not the best fit for that query, but I'm ready for other questions!", "I'm not equipped to address that question, but let's look at a different topic.", "Sorry, I can't help with that question, but I'm ready for another one.", "I can't answer that, but I'm here for anything else you need!", "That one's out of my range, but let's explore a different question.", "I'd love to assist with a different topic, as that question isn't one I can address.", "I'm unable to provide insights on that, but let's look at something else.", "I can't help with that specific question, but I'm here for others!", "That's a bit beyond my range, but let's tackle another question!", "I won't be able to answer that, but I'd love to help with something else.", "That question isn't something I can address, but let's try another topic.", "I can't tackle that question, but I'm here for anything else you might need.", "I'm unable to answer that question, but let's try another one.", "That question is beyond what I can handle, but I'm here for others!", "That one's a bit out of scope for me, but let's explore a different question.", "I don't have an answer for that, but let's tackle something else together!", "Sorry, I can't assist with that one, but I'm here for anything else!", "Unfortunately, I can't answer that, but let me know if there's something else I can do.", "I won't be able to help with that, but I'm ready for another topic!", "That one's a bit beyond my capabilities, but let's try a different question.", "That's not something I can answer, but I'm here for other queries!", 'That question goes beyond my expertise, but let me know how else I can assist.', "I can't help with that, but I'm here for other questions!", "I'm unable to answer that, but let's try another question together.", "I can't assist with that one, but I'd love to help with something else.", "I'm here to help, though that question may need a different approach.", "That question's a bit outside my range, but I'm ready for another one!", "I can't answer that one, but let me know how else I can assist."]
    return [random.choice(rejection_responses) for _ in range(n)]

ARGS = {
    "n": 5
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_not_allowed_tokens Ran
ran on a synthesized input
rhaldarpurdue/kldo/eval_utils.py
code served (permissive licence) · get_code("9558b03087afac86")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 1, dtype family int, shape (51,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

class MockTokenizer:
    def __init__(self, vocab_size=100):
        self.vocab_size = vocab_size
        self.bos_token_id = 0
        self.eos_token_id = 1
        self.pad_token_id = 2
        self.unk_token_id = 3
    
    def decode(self, token_ids):
        # Return printable ASCII for tokens 0-2, non-printable for others
        if isinstance(token_ids, list):
            if token_ids[0] < 3:
                return chr(65 + token_ids[0])  # 'A', 'B', 'C'
            else:
                return chr(0)  # Non-printable character
        return chr(65)

torch.manual_seed(0)

tokenizer = MockTokenizer(vocab_size=50)

ARGS = {
    "tokenizer": tokenizer
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 1, dtype family int, shape (51,) — shape (51,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
load_dataset Ran
ran on a synthesized input
rhaldarpurdue/kldo/eval_utils.py
code served (permissive licence) · get_code("4cc483f4696c2521")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Series. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import os
import pandas as pd
import tempfile

# Create temporary CSV file for testing
with tempfile.NamedTemporaryFile(mode='w', suffix='.csv', delete=False) as f:
    csv_path = f.name
    f.write("name,age,value\n")
    f.write("alice,25,100\n")
    f.write("bob,30,200\n")

# Create temporary TXT file for testing
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
    txt_path = f.name
    f.write("line1\n")
    f.write("line2\n")
    f.write("line3\n")

ARGS = {
    "dataset_path": csv_path,
    "column_name": "name"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
pandas — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Series — a Series output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Series output the recorded ndim 1 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
pca_reduce_dimensions Ran
ran on a synthesized input
rhaldarpurdue/kldo/metrics.py
code served (permissive licence) · get_code("36bb4333595d757f")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned PCA. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np
from sklearn.decomposition import PCA

torch.manual_seed(0)

# Create small hidden states tensor
# PCA expects a 2D array-like of shape (n_samples, n_features)
# We'll use batch_size=2, feature_dim=4
hidden_states = np.random.randn(2, 4).astype(np.float32)

# Number of components to reduce to
num_components = 2

ARGS = {
    "hidden_states": hidden_states,
    "num_components": num_components,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, sklearn, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type PCA — a PCA output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a PCA output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
prepend_sys_prompt Ran
ran on a synthesized input
rhaldarpurdue/kldo/generate.py
code served (permissive licence) · get_code("2d598ab5942a0271")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

ARGS = {
    'sentence': '  Hello, this is a test message.  ',
    'args': {}
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
generate_accepted Not yet run
unverified (harvested, no recorded run)
rhaldarpurdue/kldo/dataset_generation/generate.py
code served (permissive licence) · get_code("740872830c85598c")
How it ran

no invocation recorded.

get_hidden_states Not yet run
unverified (harvested, no recorded run)
rhaldarpurdue/kldo/metrics.py
code served (permissive licence) · get_code("73d2eea3309d497e")
How it ran

no invocation recorded.

get_response Not yet run
unverified (harvested, no recorded run)
rhaldarpurdue/kldo/dataset_generation/compare.py
code served (permissive licence) · get_code("962f72a6b771258f")
How it ran

no invocation recorded.

load_model_and_tokenizer Not yet run
unverified (harvested, no recorded run)
rhaldarpurdue/kldo/eval_utils.py
code served (permissive licence) · get_code("63fd436cd288e12f")
How it ran

no invocation recorded.

load_model_and_tokenizer Not yet run
unverified (harvested, no recorded run)
rhaldarpurdue/kldo/dataset_generation/compare.py
code served (permissive licence) · get_code("d690eaa700e23094")
How it ran

no invocation recorded.

load_model_and_tokenizer Not yet run
unverified (harvested, no recorded run)
rhaldarpurdue/kldo/dataset_generation/generate.py
code served (permissive licence) · get_code("b95843089da1efe9")
How it ran

no invocation recorded.

process_soft_prompt_as_word_embedding Not yet run
unverified (harvested, no recorded run)
rhaldarpurdue/kldo/generate.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from chujiezheng/LLM-Safeguard, is pointer only (licence: NONE) · get_code("da8ca4544aefb294")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from chujiezheng/LLM-Safeguard, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

response_list Not yet run
unverified (harvested, no recorded run)
rhaldarpurdue/kldo/dataset_generation/compare.py
code served (permissive licence) · get_code("8257f273d387a13e")
How it ran

no invocation recorded.

Also present in other papers' code

Of 17 samples lifted from this paper's linked repositories, 17 carry a function identity and 0 do not. Of the 16 distinct functions with an identity, 2 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 0 the same month, 0 later) and 14 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
generate 1 other paper
1 dated earlier
2401.18018 (2024-01)
On Prompt-Driven Safeguarding for Large Language Models
process_soft_prompt_as_word_embedding 1 other paper
1 dated earlier
2401.18018 (2024-01)
On Prompt-Driven Safeguarding for Large Language Models

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

We present a theoretical framework showing that popular LLM alignment methods-including RLHF and its variants-can be understood as divergence estimators between aligned (safe or preferred) and unaligned (harmful or less-preferred) distributions. This perspective explains the emergence of separation in the latent space between safe and harmful prompts after alignment. As an application of our general divergence framework, we propose KLDO, a novel KL divergence-based alignment method, and empirically validate its effectiveness. We further show that using compliance-refusal datasets, rather than standard preference-based datasets, leads to stronger separation and improved safety alignment. Finally, to quantify the separation effect, we propose a distance-based metric in the prompt representation space, which also acts as a statistically significant indicator for model safety.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2502.00657")
get_code_for_paper("2502.00657")
have("2502.00657")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2502.00657.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2502.00657.svg)](https://syntology.ai/paper/2502.00657)

Connect an agent — have() is free.