SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2405.00218 · 2024

Constrained Decoding for Secure Code Generation

arXiv · PDF · Open in the Atlas

Code that ran

9 of 13 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; 6 failures of our instrument; 4 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/2405.00218.json · badge: /api/ran/2405.00218.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
dynamite321/codeguardplus canonical (classifier label)
classifier basis: census
9 ran · 4 no recorded run
FunctionStatusWhere it lives
confidence_interval Ran
ran, violated the contract we drafted
dynamite321/codeguardplus/correctness_eval.py
code served (permissive licence) · get_code("4bd827a4fdf8d096")
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, 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 scipy.stats
import numpy as np

# The function takes:
# - data: an array-like object of numeric values
# - confidence: a float representing confidence level (default 0.95)

# Looking at the function body:
# - data is converted to numpy array
# - len() is called on it
# - np.mean() and scipy.stats.sem() are called on it
# - scipy.stats.t.ppf() is used with n-1 degrees of freedom

# Create sample data - a simple list of numbers
data = [1.2, 2.3, 3.1, 2.9, 3.5, 2.8, 3.2, 2.7]

# Standard confidence level
confidence = 0.95

ARGS = {
    "data": data,
    "confidence": confidence
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, scipy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple 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
duplicate_interleave Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
dynamite321/codeguardplus/inference/hf/modeling_codegen.py
pointer only (licence: MIT); the stored copy get_code serves, from Cranial-XIX/longhorn, is pointer only (licence: NONE) · get_code("03e99c761c545617")
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 Cranial-XIX/longhorn, 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.

fixed_pos_embedding Ran
ran; our contract draft was wrong, not the code
dynamite321/codeguardplus/inference/hf/modeling_codegen.py
code served (permissive licence) · get_code("7ea21b9da7ef5be6")
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, 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 torch

torch.manual_seed(0)

# Create a small tensor with shape (batch=2, seq_len=3, dim=4)
# The function uses x.shape[-1] for dim and x.shape[seq_dim] for seq_len
x = torch.randn(2, 3, 4)

# seq_dim parameter - which dimension contains the sequence
seq_dim = 1

# seq_len parameter - can be None (will use x.shape[seq_dim]) or explicitly set
seq_len = None

ARGS = {
    "x": x,
    "seq_dim": seq_dim,
    "seq_len": seq_len,
}
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 tuple, ndim 3, dtype family float — a tuple 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_old_stats_json Ran
ran; our contract draft was wrong, not the code
dynamite321/codeguardplus/new_stats.py
code served (permissive licence) · get_code("5fe250b209299fb2")
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 tempfile
import json
import os

# Create a temporary directory structure with stat.json files
temp_dir = tempfile.mkdtemp()

# Create nested directories with stat.json files
os.makedirs(os.path.join(temp_dir, 'subdir1'), exist_ok=True)
os.makedirs(os.path.join(temp_dir, 'subdir2', 'nested'), exist_ok=True)

# Create stat.json files with sample data
stat_data_1 = {'metric1': 0.95, 'metric2': 0.87}
stat_data_2 = {'metric1': 0.92, 'metric2': 0.89}
stat_data_3 = {'metric1': 0.98, 'metric2': 0.91}

with open(os.path.join(temp_dir, 'stat.json'), 'w') as f:
    json.dump(stat_data_1, f)

with open(os.path.join(temp_dir, 'subdir1', 'stat.json'), 'w') as f:
    json.dump(stat_data_2, f)

with open(os.path.join(temp_dir, 'subdir2', 'nested', 'stat.json'), 'w') as f:
    json.dump(stat_data_3, f)

ARGS = {
    'base_path': temp_dir
}
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 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
get_prompt Ran
ran; our contract draft was wrong, not the code
dynamite321/codeguardplus/correctness_eval.py
code served (permissive licence) · get_code("718990946e149fe1")
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, 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 os
import json
import tempfile
import shutil

# Create a temporary directory structure to mock the data/base directory
temp_dir = tempfile.mkdtemp()
base_path = os.path.join(temp_dir, 'data', 'base')
os.makedirs(base_path, exist_ok=True)

# Create a vulnerability type and scenario directory
vul_type = 'sql_injection'
scenario = 'scenario_1'
scenario_path = os.path.join(base_path, vul_type, scenario)
os.makedirs(scenario_path, exist_ok=True)

# Create info.json
info_data = {
    'language': 'py'
}
with open(os.path.join(scenario_path, 'info.json'), 'w') as f:
    json.dump(info_data, f)

# Create file_context.py
file_context_content = "# This is file context\ndef vulnerable_function():\n    pass\n"
with open(os.path.join(scenario_path, 'file_context.py'), 'w') as f:
    f.write(file_context_content)

# Create func_context.py
func_context_content = "# This is function context\nuser_input = request.args.get('id')\n"
with open(os.path.join(scenario_path, 'func_context.py'), 'w') as f:
    f.write(func_context_content)

# Change to temp_dir so relative paths work
original_cwd = os.getcwd()
os.chdir(temp_dir)

# Define the arguments
ARGS = {
    'vul_type': 'sql_injection',
    'scenario': 'scenario_1'
}
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 tuple, ndim 1, dtype family float — a tuple 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_sonar_scans Ran
ran; our contract draft was wrong, not the code
dynamite321/codeguardplus/new_stats.py
code served (permissive licence) · get_code("da54b6705bc5cee8")
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 os
import json
import tempfile
import shutil

# Create a temporary directory with test JSON files
temp_dir = tempfile.mkdtemp()

# Create test scan data
scan_data_1 = [
    {"id": 1, "value": "scan1"},
    {"id": 2, "value": "scan2"}
]

scan_data_2 = [
    {"id": 3, "value": "scan3"}
]

# Write JSON files to temp directory
with open(os.path.join(temp_dir, 'scan_001.json'), 'w') as f:
    json.dump(scan_data_1, f)

with open(os.path.join(temp_dir, 'scan_002.json'), 'w') as f:
    json.dump(scan_data_2, f)

# Create a .swp file that should be skipped
with open(os.path.join(temp_dir, 'scan_003.json.swp'), 'w') as f:
    json.dump([], f)

# Create an empty JSON file
with open(os.path.join(temp_dir, 'empty.json'), 'w') as f:
    json.dump([], f)

ARGS = {
    'base_path': temp_dir
}
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
pass_at_k Ran
ran, honoured the contract we drafted
dynamite321/codeguardplus/correctness_eval.py
code served (permissive licence) · get_code("aaf864304de22b06")
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

# Analyzing the pass_at_k function:
# - n: total number of samples (used in comparisons and np.arange)
# - c: number of correct samples (used in comparisons)
# - k: number of passes/attempts (used in division)
# All parameters are numeric values used in arithmetic operations

ARGS = {
    "n": 100,
    "c": 25,
    "k": 10
}
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
rotate_every_two Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
dynamite321/codeguardplus/inference/hf/modeling_codegen.py
code served (permissive licence) · get_code("621a8a98538cd46d")
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 4, dtype family float, shape (2, 3, 4, 6) 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

torch.manual_seed(0)

def rotate_every_two(x):
    x1 = x[:, :, :, ::2]
    x2 = x[:, :, :, 1::2]
    x = torch.stack((-x2, x1), dim=-1)
    return x.flatten(-2)

# The function takes a single parameter 'x' which is a tensor
# It performs slicing on dimension -1 (last dimension), so we need at least 2 elements
# It uses stack and flatten operations
# Shape: (batch, dim1, dim2, even_last_dim) for proper slicing
x = torch.randn(2, 3, 4, 6)

ARGS = {
    "x": x
}
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 4, dtype family float, shape (2, 3, 4, 6) — shape (2, 3, 4, 6) 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
try_parse Ran
ran, honoured the contract we drafted
dynamite321/codeguardplus/codeql_eval.py
code served (permissive licence) · get_code("b147b5e666ea522a")
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 ast
import subprocess

ARGS = {
    "code": "x = 1 + 2\nprint(x)",
    "lang": "py"
}
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 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
complete_scan Not yet run
unverified (harvested, no recorded run)
dynamite321/codeguardplus/sonar_scan.py
code served (permissive licence) · get_code("3ed1db97a93b601c")
How it ran

no invocation recorded.

config_from_pretrained Not yet run
unverified (harvested, no recorded run)
dynamite321/codeguardplus/inference/model.py
code served (permissive licence) · get_code("e1b5a2d510fa54d0")
How it ran

no invocation recorded.

get_insecure_files Not yet run
unverified (harvested, no recorded run)
dynamite321/codeguardplus/sonar_scan.py
code served (permissive licence) · get_code("957d15e0dd9a41e0")
How it ran

no invocation recorded.

new_project Not yet run
unverified (harvested, no recorded run)
dynamite321/codeguardplus/sonar_scan.py
code served (permissive licence) · get_code("8a519fe4005f6a16")
How it ran

no invocation recorded.

Also present in other papers' code

Of 13 samples lifted from this paper's linked repositories, 13 carry a function identity and 0 do not. Of the 13 distinct functions with an identity, 4 are also present in other papers whose code we hold (3 with at least one paper dated earlier, 0 the same month, 3 later) and 9 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
duplicate_interleave 7 other papers
5 dated earlier, 1 later, 1 same year, order not determinable
2206.13517 (2022-06)
ProGen2: Exploring the Boundaries of Protein Language Models
2307.04349 (2023-07)
RLTF: Reinforcement Learning from Unit Test Feedback
2307.08621 (2023-07)
Retentive Network: A Successor to Transformer for Large Language Models
and 4 more not named here
rotate_every_two 5 other papers
4 dated earlier, 1 later
2206.13517 (2022-06)
ProGen2: Exploring the Boundaries of Protein Language Models
2307.04349 (2023-07)
RLTF: Reinforcement Learning from Unit Test Feedback
2308.10882 (2023-08)
Giraffe: Adventures in Expanding Context Lengths in LLMs
and 2 more not named here
fixed_pos_embedding 3 other papers
3 dated earlier
2206.13517 (2022-06)
ProGen2: Exploring the Boundaries of Protein Language Models
2307.04349 (2023-07)
RLTF: Reinforcement Learning from Unit Test Feedback
2309.01327 (2023-09)
Can I Trust Your Answer? Visually Grounded Video Question Answering
try_parse 1 other paper
1 later
2510.18204 (2025-10)
RESCUE: Retrieval Augmented Secure Code Generation

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

Code Large Language Models (Code LLMs) have been increasingly used by developers to boost productivity, but they often generate vulnerable code. Thus, there is an urgent need to ensure that code generated by Code LLMs is correct and secure. Previous research has primarily focused on generating secure code, overlooking the fact that secure code also needs to be correct. This oversight can lead to a false sense of security. Currently, the community lacks a method to measure actual progress in this area, and we need solutions that address both security and correctness of code generation. This paper introduces a new benchmark, CodeGuard+, along with two new metrics, to measure Code LLMs' ability to generate both secure and correct code. Using our new evaluation methods, we show that the state-of-the-art defense technique, prefix tuning, may not be as strong as previously believed, since it generates secure code but sacrifices functional correctness. We also demonstrate that different decoding methods significantly affect the security of Code LLMs. Furthermore, we explore a new defense direction: constrained decoding for secure code generation. We propose new constrained decoding techniques to generate secure code. Our results reveal that constrained decoding is more effective than prefix tuning to improve the security of Code LLMs, without requiring a specialized training dataset. Moreover, our evaluations over eight state-of-the-art Code LLMs show that constrained decoding has strong performance to improve the security of Code LLMs, and our technique outperforms GPT-4.

For agents

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

get_harvested_code_for_paper("2405.00218")
get_code_for_paper("2405.00218")
have("2405.00218")

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

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

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

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

Connect an agent — have() is free.