SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2025.emnlp-main.1010 · EMNLP · 2025

SAFENUDGE: Safeguarding Large Language Models in Real-time with Tunable Safety-Performance Trade-offs Warning: this article contains sensitive content

Julia Stoyanovich, Andrew Bell, Joao Fonseca

Open in the Atlas

Code that ran

6 of 9 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; 1 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 3 failures of our instrument; 3 no recorded run), measured 2026-11-24; 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/2025.emnlp-main.1010.json · badge: /api/ran/2025.emnlp-main.1010.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
joaopfonseca/SafeNudge canonical (classifier label)
classifier basis: census
6 ran · 3 no recorded run
FunctionStatusWhere it lives
conflict_make Ran
ran; our contract draft was wrong, not the code
joaopfonseca/SafeNudge/ctg/instructions_registry.py
code served (permissive licence) · get_code("cd24b41647f51d39")
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 dict. 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

# Construct a conflicts dictionary
# Keys are instruction ids (integers), values are sets of conflicting instruction ids
conflicts = {
    0: {1, 2},
    1: {2},
    2: set(),
    3: {0},
}

ARGS = {
    "conflicts": conflicts
}
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 dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
count_words Ran
ran, honoured the contract we drafted
joaopfonseca/SafeNudge/ctg/instructions_util.py
pointer only (licence: MIT); the stored copy get_code serves, from dongguanting/FollowRAG, is pointer only (licence: NONE) · get_code("cdcc85ca09b00f7e")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from dongguanting/FollowRAG, 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.

format_all_perf Ran
ran on a synthesized input
joaopfonseca/SafeNudge/experiments/analysis.py
code served (permissive licence) · get_code("77055c9da8fc92c8")
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 DataFrame. 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 pandas as pd
import numpy as np

# Create sample dataframes to pass to format_all_perf
# The function expects a list of dataframes that will be concatenated

# Create first dataframe with Dataset='A'
df1 = pd.DataFrame({
    'metric1': [0.85, 0.90],
    'metric2': [0.75, 0.80],
    'Dataset': ['A', 'A']
}, index=['HBI_model1|ResNet', 'HBI_model2|VGG'])

# Create second dataframe with Dataset='B' and 'A|B'
df2 = pd.DataFrame({
    'metric1': [0.88, 0.92],
    'metric2': [0.78, 0.82],
    'Dataset': ['B', 'C']
}, index=['HBI_model3|DenseNet', 'other_model4|EfficientNet'])

# Create third dataframe
df3 = pd.DataFrame({
    'metric1': [0.87],
    'metric2': [0.77],
    'Dataset': ['A']
}, index=['HBI_model5|MobileNet'])

all_perf = [df1, df2, df3]

ARGS = {
    'all_perf': all_perf
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, pandas — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type DataFrame — a DataFrame output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a DataFrame output the recorded ndim 2 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
get_mean_sem_results Ran
ran on a synthesized input
joaopfonseca/SafeNudge/experiments/analysis.py
code served (permissive licence) · get_code("86b24a3a4aa66eae")
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 3, 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 pandas as pd
import numpy as np

# Create a small sample DataFrame that matches what get_mean_sem_results expects
# The function groups by 'param_est_name', selects the row with max 'mean_test_f1',
# then extracts columns starting with 'mean_test_' and 'std_test_'

data = {
    'param_est_name': ['model_a', 'model_a', 'model_b', 'model_b'],
    'mean_test_f1': [0.7, 0.85, 0.75, 0.80],
    'mean_test_precision': [0.72, 0.87, 0.76, 0.82],
    'mean_test_recall': [0.68, 0.83, 0.74, 0.78],
    'std_test_f1': [0.05, 0.03, 0.04, 0.02],
    'std_test_precision': [0.06, 0.04, 0.05, 0.03],
    'std_test_recall': [0.04, 0.02, 0.03, 0.01],
    'other_column': [1, 2, 3, 4]
}

results_df = pd.DataFrame(data)

ARGS = {
    'results': results_df
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, pandas — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 3, 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
read_prompt_list Ran
ran; our contract draft was wrong, not the code
joaopfonseca/SafeNudge/ctg/evaluation_main.py
code served (permissive licence) · get_code("688320f8e08335ac")
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 dataclasses
import json
import tempfile
import os
from typing import Dict, Optional, Union

@dataclasses.dataclass
class InputExample:
    key: int
    instruction_id_list: list
    prompt: str
    kwargs: list

def read_prompt_list(input_jsonl_filename):
    """Read inputs from jsonl."""
    inputs = []
    with open(input_jsonl_filename, 'r') as f:
        for l in f:
            example = json.loads(l)
            inputs.append(InputExample(key=example['key'], instruction_id_list=example['instruction_id_list'], prompt=example['prompt'], kwargs=example['kwargs']))
    return inputs

# Create a temporary JSONL file with sample data
temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.jsonl')
temp_filename = temp_file.name

# Write sample data to the temporary file
sample_data = [
    {
        "key": 1,
        "instruction_id_list": ["inst_1", "inst_2"],
        "prompt": "What is 2+2?",
        "kwargs": [{"param1": "value1", "param2": 42}, {"param3": "value3", "param4": None}]
    },
    {
        "key": 2,
        "instruction_id_list": ["inst_3"],
        "prompt": "Explain recursion",
        "kwargs": [{"nested": "data", "count": 10}]
    }
]

for line in sample_data:
    temp_file.write(json.dumps(line) + '\n')

temp_file.close()

ARGS = {
    'input_jsonl_filename': temp_filename
}
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
split_into_sentences Ran
ran; our contract draft was wrong, not the code
joaopfonseca/SafeNudge/ctg/instructions_util.py
code served (permissive licence) · get_code("a87fa9a878e94aa6")
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 re

def split_into_sentences(text):
    """Split the text into sentences.

    Args:
      text: A string that consists of more than or equal to one sentences.

    Returns:
      A list of strings where each string is a sentence.
    """
    _ALPHABETS = '([A-Za-z])'
    _PREFIXES = '(Mr|St|Mrs|Ms|Dr)[.]'
    _SUFFIXES = '(Inc|Ltd|Jr|Sr|Co)'
    _STARTERS = '(Mr|Mrs|Ms|Dr|Prof|Capt|Cpt|Lt|He\\s|She\\s|It\\s|They\\s|Their\\s|Our\\s|We\\s|But\\s|However\\s|That\\s|This\\s|Wherever)'
    _ACRONYMS = '([A-Z][.][A-Z][.](?:[A-Z][.])?)'
    _WEBSITES = '[.](com|net|org|io|gov|edu|me)'
    _DIGITS = '([0-9])'
    _MULTIPLE_DOTS = '\\.{2,}'
    
    text = ' ' + text + '  '
    text = text.replace('\n', ' ')
    text = re.sub(_PREFIXES, '\\1<prd>', text)
    text = re.sub(_WEBSITES, '<prd>\\1', text)
    text = re.sub(_DIGITS + '[.]' + _DIGITS, '\\1<prd>\\2', text)
    text = re.sub(_MULTIPLE_DOTS, lambda match: '<prd>' * len(match.group(0)) + '<stop>', text)
    if 'Ph.D' in text:
        text = text.replace('Ph.D.', 'Ph<prd>D<prd>')
    text = re.sub('\\s' + _ALPHABETS + '[.] ', ' \\1<prd> ', text)
    text = re.sub(_ACRONYMS + ' ' + _STARTERS, '\\1<stop> \\2', text)
    text = re.sub(_ALPHABETS + '[.]' + _ALPHABETS + '[.]' + _ALPHABETS + '[.]', '\\1<prd>\\2<prd>\\3<prd>', text)
    text = re.sub(_ALPHABETS + '[.]' + _ALPHABETS + '[.]', '\\1<prd>\\2<prd>', text)
    text = re.sub(' ' + _SUFFIXES + '[.] ' + _STARTERS, ' \\1<stop> \\2', text)
    text = re.sub(' ' + _SUFFIXES + '[.]', ' \\1<prd>', text)
    text = re.sub(' ' + _ALPHABETS + '[.]', ' \\1<prd>', text)
    if '"' in text:
        text = text.replace('."', '".')
    if '"' in text:
        text = text.replace('."', '".')
    if '!' in text:
        text = text.replace('!"', '"!')
    if '?' in text:
        text = text.replace('?"', '"?')
    text = text.replace('.', '.<stop>')
    text = text.replace('?', '?<stop>')
    text = text.replace('!', '!<stop>')
    text = text.replace('<prd>', '.')
    sentences = text.split('<stop>')
    sentences = [s.strip() for s in sentences]
    if sentences and (not sentences[-1]):
        sentences = sentences[:-1]
    return sentences


ARGS = {
    'text': 'Hello world. This is a test. Dr. Smith works at Google.com. What is your name? It is great!'
}
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
count_sentences Not yet run
unverified (harvested, no recorded run)
joaopfonseca/SafeNudge/ctg/instructions_util.py
pointer only (licence: MIT); the stored copy get_code serves, from dongguanting/FollowRAG, is pointer only (licence: NONE) · get_code("f79646ddd0a03162")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from dongguanting/FollowRAG, 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.

test_instruction_following_loose Not yet run
unverified (harvested, no recorded run)
joaopfonseca/SafeNudge/ctg/evaluation_main.py
code served (permissive licence) · get_code("311b94e93f19adb1")
How it ran

no invocation recorded.

test_instruction_following_strict Not yet run
unverified (harvested, no recorded run)
joaopfonseca/SafeNudge/ctg/evaluation_main.py
code served (permissive licence) · get_code("9f12a7b872f44814")
How it ran

no invocation recorded.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 distinct functions with an identity, 5 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 0 the same month, 3 later) and 4 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
split_into_sentences 8 other papers
6 dated earlier, 2 later
2309.00071 (2023-09)
YaRN: Efficient Context Window Extension of Large Language Models
2311.07911 (2023-11)
Instruction-Following Evaluation for Large Language Models
2404.15846 (2024-04)
From Complex to Simple: Enhancing Multi-Constraint Complex Instruction Following Ability of Large Language Models
and 5 more not named here
conflict_make 6 other papers
4 dated earlier, 2 later
2309.00071 (2023-09)
YaRN: Efficient Context Window Extension of Large Language Models
2311.07911 (2023-11)
Instruction-Following Evaluation for Large Language Models
2404.15846 (2024-04)
From Complex to Simple: Enhancing Multi-Constraint Complex Instruction Following Ability of Large Language Models
and 3 more not named here
count_words 6 other papers
6 dated earlier
2309.00071 (2023-09)
YaRN: Efficient Context Window Extension of Large Language Models
2311.07911 (2023-11)
Instruction-Following Evaluation for Large Language Models
2401.16745 (2024-01)
MT-Eval: A Multi-Turn Capabilities Evaluation Benchmark for Large Language Models
and 3 more not named here
count_sentences 5 other papers
5 dated earlier
2309.00071 (2023-09)
YaRN: Efficient Context Window Extension of Large Language Models
2311.07911 (2023-11)
Instruction-Following Evaluation for Large Language Models
2404.15846 (2024-04)
From Complex to Simple: Enhancing Multi-Constraint Complex Instruction Following Ability of Large Language Models
and 2 more not named here
read_prompt_list 2 other papers
1 later, 1 same year, order not determinable
2505.19037 (2025-05)
Speech-IFEval: Evaluating Instruction-Following and Quantifying Catastrophic Forgetting in Speech-Aware Language Models
2604.02795 (2026-04)
Rubrics to Tokens: Bridging Response-level Rubrics and Token-level Rewards in Instruction Following Tasks

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-24.

Repositories linked to this paper

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

Abstract

Large Language Models (LLMs) have been shown to be susceptible to jailbreak attacks, or adversarial attacks used to illicit high risk behavior from a model, highlighting the critical need to safeguard widely-deployed models. Safeguarding approaches, which include finetuning models or having LLMs "self-reflect," may lengthen the inference time of a model, incur a computational penalty, reduce the semantic fluency of an output, and restrict "normal" model behavior. Importantly, these Safety-Performance Trade-offs (SPTs) remain an understudied area. In this work, we make three contributions: (1) We introduce SAFENUDGE, a novel safeguard that combines Controlled Text Generation and "nudging." SAFENUDGE triggers during text-generation while a jailbreak attack is being executed, and can reduce successful jailbreak attempts by between 28.1% and 37.3% by guiding the LLM towards a safe response. It adds minimal latency to inference and has a negligible impact on the semantic fluency of outputs. Second, it supports tunable SPTs, meaning practitioners can set their own tolerance for tradeoffs balancing safety and restrictions to normal model behavior. Third, we release the source code for SAFENUDGE at https:// github.com/joaopfonseca/SafeNudge. It is open source and compatible with the Hugging Face transformers library.

For agents

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

get_harvested_code_for_paper("2025.emnlp-main.1010")
get_code_for_paper("2025.emnlp-main.1010")
have("2025.emnlp-main.1010")

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

curl https://syntology.ai/api/ran/2025.emnlp-main.1010.json

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

[![Syntology run record](https://syntology.ai/api/ran/2025.emnlp-main.1010.svg)](https://syntology.ai/paper/2025.emnlp-main.1010)

Connect an agent — have() is free.