SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2510.04398 · NeurIPS · 2025

SECA: Semantically Equivalent and Coherent Attacks for Eliciting LLM Hallucinations

René Vidal, Liangzu Peng, Buyun Liang, Jinqi Luo, Kwan Ho, Ryan Chan, Darshan Thaker

arXiv · PDF · Open in the Atlas

Code that ran

8 of 11 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; 2 honoured the contract we drafted, 1 violated it and 0 have no contract verdict; 5 failures of our instrument; 3 no recorded run), measured 2026-11-23; 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/2510.04398.json · badge: /api/ran/2510.04398.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
Buyun-Liang/SECA community
Papers with Code archive
8 ran · 3 no recorded run
FunctionStatusWhere it lives
feasibility_check Ran
ran, violated the contract we drafted
Buyun-Liang/SECA/src/seca.py
code served (permissive licence) · get_code("d354dde7f3226fed")
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 bool, ndim 0, dtype family float, shape () 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 json
import torch
import torch.nn as nn

# Create a mock feasibility evaluator model
class MockFeasibilityEvaluator(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(10, 1)
    
    def generate(self, messages, max_new_tokens=10, temperature=0.0):
        """Mock generate method that returns a valid JSON response"""
        # Return a valid JSON string with equivalence_score
        return '{"equivalence_score": "1"}'

# Create instances for the function arguments
query_x = "What is the capital of France and its significance?"
query_x0 = "What is the capital of France?"
choices = ["Paris", "Lyon", "Marseille", "Nice"]
subject = "geography"
ground_truth_idx = 0
feasibility_evaluator_model = MockFeasibilityEvaluator()

# Construct ARGS dictionary with all parameters
ARGS = {
    'query_x': query_x,
    'query_x0': query_x0,
    'choices': choices,
    'subject': subject,
    'ground_truth_idx': ground_truth_idx,
    'feasibility_evaluator_model': feasibility_evaluator_model
}
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 bool, ndim 0, dtype family float, shape () — shape () 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
get_new_parents_list Ran
ran; our contract draft was wrong, not the code
Buyun-Liang/SECA/src/seca.py
code served (permissive licence) · get_code("5043517b4a24afe0")
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 2, 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 numpy as np

class Args:
    def __init__(self):
        self.top_N_most_adversarial = 2

# Create args object
args = Args()

# candidate_parent_list is a list of tuples where each tuple contains
# an item (index 0) and a score (index 1) used for sorting
candidate_parent_list = [
    ("candidate_1", 0.9),
    ("candidate_2", 0.7),
    ("candidate_3", 0.5),
]

# parents_list is a list of tuples with same structure
parents_list = [
    ("parent_1", 0.8),
    ("parent_2", 0.6),
    ("parent_3", 0.4),
]

ARGS = {
    "args": args,
    "candidate_parent_list": candidate_parent_list,
    "parents_list": parents_list,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 2, 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_probs Ran
ran, honoured the contract we drafted
Buyun-Liang/SECA/src/seca.py
code served (permissive licence) · get_code("c908cca1a7b8292d")
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)

# Create a minimal args class with required attributes
class Args:
    def __init__(self):
        self.target_llm = 'llama3_8b'
        self.verbose = True

# Create a minimal outputs object with logits attribute
class Outputs:
    def __init__(self):
        # logits shape: [batch_size, seq_len, vocab_size]
        # We need outputs.logits[0, -1, :] to work
        # The function indexes [0, -1, :] to get the first token's last position logits
        # vocab_size needs to be large enough to contain token ids like 426, 425, etc.
        self.logits = torch.randn(2, 4, 50000)

args = Args()
outputs = Outputs()

ARGS = {
    'args': args,
    'outputs': outputs
}
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
get_prompt Ran
ran; our contract draft was wrong, not the code
Buyun-Liang/SECA/src/seca.py
code served (permissive licence) · get_code("cf0a660abde18864")
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 str. 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

torch.manual_seed(0)

# Create a minimal args object with target_llm attribute
class Args:
    def __init__(self):
        self.target_llm = "gpt-3.5-turbo"

args = Args()

# Query string - the question being asked
query_x = "What is the capital of France?"

# Current task dictionary with subject and choices
current_task_dict = {
    'subject': 'world_geography',
    'choices': [
        'London',
        'Paris',
        'Berlin',
        'Madrid'
    ]
}

# Final answer token (optional, can be None or a letter)
final_answer_token = 'B'

# Map all parameters to ARGS
ARGS = {
    'args': args,
    'query_x': query_x,
    'current_task_dict': current_task_dict,
    'final_answer_token': final_answer_token
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
get_second_largest_choice_index Ran
ran, honoured the contract we drafted
Buyun-Liang/SECA/src/seca.py
code served (permissive licence) · get_code("b74243272d5f3d61")
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 int, ndim 0, dtype family int, shape () 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
import numpy as np
from unittest.mock import Mock, MagicMock

torch.manual_seed(0)

# Create a minimal args object
class Args:
    def __init__(self):
        self.target_llm = 'llama3_8b'
        self.verbose = False

args = Args()

# Create a minimal tokenizer
class MinimalTokenizer:
    def __call__(self, text, return_tensors=None):
        # Return a mock input_ids tensor
        result = Mock()
        result.to = Mock(return_value={
            'input_ids': torch.randint(0, 100, (1, 8)),
            'attention_mask': torch.ones(1, 8, dtype=torch.long)
        })
        return result

tokenizer = MinimalTokenizer()

# Create a minimal model that returns outputs with logits
class MinimalModel(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = torch.nn.Linear(10, 32000)  # vocab size for llama
    
    def forward(self, input_ids, attention_mask, max_new_tokens=None):
        # Return mock outputs with logits
        batch_size = input_ids.shape[0]
        logits = torch.randn(batch_size, 1, 32000)  # (batch, seq_len=1, vocab_size)
        result = Mock()
        result.logits = logits
        return result

model = MinimalModel()

# Device
device = 'cpu'

# Input prompt
input_prompt = "Question: What is 2+2? A) 3 B) 4 C) 5 D) 6"

# Ground truth index (0=A, 1=B, 2=C, 3=D)
ground_truth_idx = 1

ARGS = {
    'args': args,
    'input_prompt': input_prompt,
    'model': model,
    'tokenizer': tokenizer,
    'device': device,
    'ground_truth_idx': ground_truth_idx
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, openai, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () 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
obj_fun Ran
ran; our contract draft was wrong, not the code
Buyun-Liang/SECA/src/seca.py
code served (permissive licence) · get_code("48ba4eab96fc8312")
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 tuple. 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 unittest.mock import MagicMock

torch.manual_seed(0)

# Create a minimal args object
class Args:
    def __init__(self):
        self.target_llm = 'llama3_8b'
        self.verbose = False

args = Args()

# Create a minimal tokenizer that has __call__ method
class MinimalTokenizer:
    def __call__(self, text, return_tensors=None):
        # Return a mock that has .to() method
        result = MagicMock()
        result.to = MagicMock(return_value={
            'input_ids': torch.randint(0, 1000, (1, 5)),
            'attention_mask': torch.ones(1, 5)
        })
        return result

tokenizer = MinimalTokenizer()

# Create a minimal model that returns outputs with logits
class MinimalModel(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = torch.nn.Linear(4, 32000)
    
    def forward(self, input_ids, attention_mask=None, max_new_tokens=None):
        # Return mock outputs with logits attribute
        batch_size = input_ids.shape[0] if input_ids is not None else 1
        outputs = MagicMock()
        # logits shape: (batch_size, sequence_length, vocab_size)
        outputs.logits = torch.randn(batch_size, 1, 32000)
        return outputs

model = MinimalModel()

# Create device
device = 'cpu'

# Create input prompt and target choice index
input_prompt = "What is 2+2? A) 3 B) 4 C) 5 D) 6"
target_choice_index = 1  # Index for choice B

ARGS = {
    'args': args,
    'input_prompt': input_prompt,
    'target_choice_index': target_choice_index,
    'model': model,
    'tokenizer': tokenizer,
    'device': device
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, openai, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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
semantic_equivalence_proposer Ran
ran; our contract draft was wrong, not the code
Buyun-Liang/SECA/src/seca.py
code served (permissive licence) · get_code("0b2fdf45cd9667d3")
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 str. 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 json
import random

class MockLLM:
    """Mock LLM that simulates the generate method."""
    def generate(self, messages, max_new_tokens=200, temperature=1.0, frequency_penalty=0.3, presence_penalty=0.3):
        """Return a JSON string with a new question."""
        return json.dumps({
            "new_question": "What is an alternative way to express the original concept?"
        })

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

ARGS = {
    'query_x': "What is the capital of France?",
    'subject': "geography_and_history",
    'ground_truth_index': 0,
    'choices': [
        "Paris",
        "London",
        "Berlin",
        "Madrid"
    ],
    'semantic_equivalence_proposer_LLM': MockLLM(),
    'verbose': False
}
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 str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
wrap_preserve_newlines Ran
ran; our contract draft was wrong, not the code
Buyun-Liang/SECA/src/seca.py
code served (permissive licence) · get_code("b2bb85b015b1aa7e")
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 str. 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 textwrap

def wrap_preserve_newlines(text, width):
    """Wraps text to a specified width while preserving existing newlines. This function is used for printing the long prompts"""
    lines = text.split('\n')
    wrapped_lines = [textwrap.fill(line, width=width) for line in lines]
    return '\n'.join(wrapped_lines)

ARGS = {
    'text': 'This is a long line that should be wrapped to a specified width.\nThis is another line with some text that needs wrapping.\nAnd here is a third line.',
    'width': 40
}
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 str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
get_final_answer Not yet run
unverified (harvested, no recorded run)
Buyun-Liang/SECA/src/seca.py
code served (permissive licence) · get_code("618de0ef99077865")
How it ran

no invocation recorded.

openai_get_log_probs Not yet run
unverified (harvested, no recorded run)
Buyun-Liang/SECA/src/seca.py
code served (permissive licence) · get_code("977374326178f537")
How it ran

no invocation recorded.

seca Not yet run
unverified (harvested, no recorded run)
Buyun-Liang/SECA/src/seca.py
code served (permissive licence) · get_code("418fceafa5cdb4e2")
How it ran

no invocation recorded.

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 11 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 11 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.

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

Repositories linked to this paper

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

Abstract

Warning: This method may be misused for malicious purposes. Large Language Models (LLMs) are increasingly deployed in high-risk domains. However, state-of-the-art LLMs often exhibit hallucinations, raising serious concerns about their reliability. Prior work has explored adversarial attacks to elicit hallucinations in LLMs, but these methods often rely on unrealistic prompts, either by inserting nonsensical tokens or by altering the original semantic intent. Consequently, such approaches provide limited insight into how hallucinations arise in real-world settings. In contrast, adversarial attacks in computer vision typically involve realistic modifications to input images. However, the problem of identifying realistic adversarial prompts for eliciting LLM hallucinations remains largely underexplored. To address this gap, we propose Semantically Equivalent and Coherent Attacks (SECA), which elicit hallucinations via realistic modifications to the prompt that preserve its meaning while maintaining semantic coherence. Our contributions are threefold: (i) we formulate finding realistic attacks for hallucination elicitation as a constrained optimization problem over the input prompt space under semantic equivalence and coherence constraints; (ii) we introduce a constraint-preserving zeroth-order method to effectively search for adversarial yet feasible prompts; and (iii) we demonstrate through experiments on open-ended multiple-choice question answering tasks that SECA achieves higher attack success rates while incurring almost no semantic equivalence or semantic coherence errors compared to existing methods. SECA highlights the sensitivity of both open-source and commercial gradient-inaccessible LLMs to realistic and plausible prompt variations. Code is available at https://github.com/Buyun-Liang/SECA.

For agents

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

get_harvested_code_for_paper("2510.04398")
get_code_for_paper("2510.04398")
have("2510.04398")

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

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

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

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

Connect an agent — have() is free.