AI-TechScienceGovernmentBusinessSportsEntertainment
AI-Tech

Adjusting internal model pathways helps automated coding tools write safer software

Simultaneous steering of security and correctness directions inside neural networks reduces code flaws without requiring costly model retraining, according to new research.

This article has been updated · 26 Nov see what changed
Adjusting internal model pathways helps automated coding tools write safer software
Source: Martin Vorel (CC BY-SA 4.0)
Published13 Nov 2026, 14:15 Last updated26 Nov 2026, 18:10 Sources
Source mode Marks each sentence drawn from a source or a contributor

Software developers increasingly rely on automated language models to draft functions, complete complex routines, and speed up routine programming tasks. Yet these systems frequently reproduce insecure patterns found in their training data, introducing subtle security flaws such as unsafe memory access or improper input sanitisation directly into newly created code. When an artificial intelligence system drafts software, it selects each subsequent token based on statistical patterns across vast collections of text, with no built-in guarantee that the completed routine will operate securely in production environments.

This persistence of insecure code creates substantial practical hazards for modern digital infrastructure. Vulnerabilities written into software can remain undetected through testing, leaving applications open to remote exploits, data breaches, and system crashes once deployed. Traditional fixes usually rely on post-generation security scanners, rigid prompt instructions, or extensive retraining, each of which can degrade the functional accuracy of the code or miss subtle flaws during the initial generation process.

To understand why these errors occur, it helps to examine how an automated model constructs a program from prompt to completion. An infected or misconfigured code routine begins when an initial prompt prompts a language model to assemble syntax across dozens of internal computational layers. At each step, specialized attention mechanisms focus on earlier tokens to establish how variables, functions, and control structures fit together. The model must balance two distinct properties simultaneously: maintaining valid operational logic and ensuring protective boundary checks. If the internal pathways responsible for security checks are weak or uncoordinated with those ensuring code logic, the system completes a functional program that remains fundamentally vulnerable to exploitation.

According to a paper published in the Proceedings of the 2026 Conference on Empirical Methods in Natural Language Processing (https://aclanthology.org/2026.emnlp-main.923/), researchers Hao Yan and Ziyu Yao investigated these internal representations to pinpoint where safety decisions occur inside generative models. By tracking internal activity, the authors identified specific attention heads and layers that distinguish secure code from insecure code, and designed an intervention to guide those components during text generation.1

How can researchers guide a model toward safer code?

Targeted adjustments applied directly to internal attention heads can steer an artificial intelligence model away from insecure coding patterns while preserving program validity. Rather than retraining an entire system or attempting to catch errors after code is written, the method, named DuoSteer by the authors, applies simultaneous adjustments at inference time to two distinct internal properties: code security and functional correctness.1

To identify the specific components responsible for vulnerable code, Yan and Yao created CodeSec-Pairs, a dataset comprising 9,342 contrastive pairs of safe and vulnerable Python programs sampled from the open-source model Llama-3.1-8B-Instruct.1 By comparing internal activations between safe and unsafe versions of identical programming tasks, the researchers isolated the computational layers and attention heads most actively involved in security decisions.1

In neural representations, conceptual relationships often align along specific geometric vectors.4 Ziyu Yao, a co-author of the paper, explained that just as the linguistic difference between words like king and queen aligns with a gender vector, code properties behave similarly. Yao said in response to questions from Primary that the concepts of security and functional correctness occupy separate trajectories within the network, noting that DuoSteer works by pulling an artificial intelligence system toward both goals simultaneously.

Adjusting internal model pathways helps automated coding tools write safer software
Source: GitHub

Calibrating both directions without causing interference required a conditioned discovery process. As Yao told Primary, the researchers first applied security steering, collected verified secure outputs, and then contrasted correct and incorrect functional executions on those outputs to isolate the functional correctness vector. Applying separate steering adjustments to the distinct sets of attention heads responsible for each property allowed the system to suppress vulnerabilities without breaking functional logic.

Hao Yan, the lead author, clarified how the underlying training pairs were constructed. Yan told Primary that “CodeSec-Pairs is built for safe-versus-vulnerable pairs, not for functional correctness.” For each pair, the researchers checked that both programs parsed as standalone Python without syntax errors, while functional correctness was judged separately by GPT-4.1 and validated against human annotations with a Cohen’s kappa agreement score of about 0.87.

Where do models process security inside their networks?

Tracking internal mechanisms revealed that the attention heads carrying information about code safety are not necessarily the ones driving generation decisions. When analyzing the models, the researchers compared passive probing classifiers against active knockout interventions. Probing trains classifiers on recorded attention head outputs to predict whether a processed program is safe or vulnerable, while knockout measures how much a model preference for safe code drops when a specific head is silenced.

Yao told Primary that the two diagnostic methods produced completely divergent results, with a correlation between their head rankings that was essentially zero across every tested vulnerability type. When researchers steered the attention heads highlighted as top candidates by passive probes, the vulnerability rate barely moved across three of the five tested vulnerability categories, whereas steering the heads identified through knockouts successfully reduced vulnerabilities.

The physical location of safety processing also varied across different types of software flaws rather than residing in a uniform component. For four out of five tested vulnerability classes in Llama-3.1-8B-Instruct, the distinction between safe and vulnerable code peaked in middle layers 9 to 11 of the 32 total layers. In contrast, for improper certificate validation, where code fails to validate a server security certificate, the strongest signal appeared at the final layer. Because each vulnerability type involved its own distinct set of causally relevant attention heads, the steering vectors had to be calibrated separately for each flaw category.

What performance gains did dual steering achieve?

Across experiments evaluating five distinct vulnerability types, the DuoSteer method reduced the vulnerability rate by an average of 26.9 percent compared to unguided generation in Llama-3.1-8B-Instruct.1 At the same time, the double-steering technique improved the functional correctness of the generated Python programs by an average of 7.5 percent over baseline outputs.1 The authors reported that this dual intervention outperformed alternative single-direction steering variants, standard prompt-engineering approaches, and supervised fine-tuning baselines on the same evaluation benchmarks.1

Yan stated that the magnitude of improvement depended heavily on how consistent the underlying security fixes were. When a flaw has a uniform solution, such as escaping user text for cross-site scripting or selecting a safe loader function for deserialization, steering vectors find clear leverage. In contrast, for path traversal flaws, where 64 percent of dataset pairs lacked a dominant fix pattern, steering proved less effective on its own. Yan noted that combining steering with prompt hints offered supplementary benefits on those diffuse vulnerability classes.

On absolute functional metrics across SecCodePLT benchmarks, DuoSteer increased correctness on unsafe deserialization from 58.8 percent to 94.1 percent, on certificate validation from 41.2 percent to 60.8 percent, and on code injection from 25.5 percent to 27.5 percent in Llama-3.1-8B-Instruct. While correctness on path traversal and cross-site scripting finished below the unsteered baseline, it remained well above single-direction safety steering. When evaluated on benchmark unit tests, pass rates climbed from 62.7 percent to 88.2 percent on deserialization and from 43.1 percent to 51.0 percent on code injection.

Adjusting internal model pathways helps automated coding tools write safer software
Source: Ankerl

To determine whether the internal steering mechanism applied beyond a single architecture, the researchers evaluated the technique on a second system, Qwen-2.5-Coder-7B-Instruct.1 Testing on that model with an additional 2,500 contrastive code pairs sampled from its own outputs confirmed that coordinating safety and correctness adjustments yielded similar performance advantages.1

Regarding computational overhead, Yan explained that DuoSteer adds a fixed vector to between 16 and 128 attention heads out of the model’s 1,024 total heads per generated token. Because this operation requires no extra model passes, no parameter updates, and no gradient storage during deployment, its inference latency is negligible compared to standard generation.

What are the limits of internal steering?

These findings represent experimental observations of model behavior across specific test sets rather than a guarantee of flawless software generation in real-world environments. The measurements reflect automated evaluations on five defined vulnerability categories in Python and depend on the quality and distribution of the contrastive sample pairs used to calibrate the steering vectors. The findings have since been published in the Proceedings of the 2026 Conference on Empirical Methods in Natural Language Processing.

Steering internal activations does not provide formal mathematical verification that generated software is secure under all deployment conditions. If an underlying model encounters an unfamiliar software vulnerability class absent from its calibration data, the localized attention vectors may fail to prevent hazardous completions. The technique also requires direct computational access to internal layer activations, making it suitable for open-weight models but inapplicable to closed commercial systems accessed solely through external application programming interfaces.

Yan also emphasized that attention head locations and steering vectors are specific to each distinct model architecture and cannot be transferred directly across models. In addition, the experiments examined isolated Python functions, leaving multi-file repositories and memory-safety vulnerabilities in languages like C and C++ untested.

What questions remain for automated coding safety?

The broader adoption of internal steering depends on whether the technique generalizes across additional programming languages, larger model architectures, and complex multi-file software projects. Developers building automated coding assistants face the ongoing challenge of maintaining high computational throughput while running real-time internal interventions during inference.

Future research will need to examine whether dual-steering strategies remain effective against emerging security threats, and whether similar internal guidance can be integrated directly into training pipelines. For software engineering teams, the work suggests that analyzing and adjusting internal model representations offers a practical path toward reducing vulnerabilities before automated code ever reaches a production repository.

This piece was prepared from the published EMNLP 2026 paper and public records together with answers from Hao Yan and Ziyu Yao to seven questions from the Primary news team, completed September 2026.

Update

26 Nov 2026, 18:10 UTC — This article was updated to reflect revised text and images.

The record

31 sentences trace to 2 sources and 2 contributors.

  1. 1 HY Hao Yan, Ziyu Yao Paper · arxiv.org · 1 Sep 2026 Interpreting and Steering for Safe and Correct Code Generation Preprint · may not have been peer reviewed See the source
  2. 2 ZY Ziyu Yao, co-author Contributor · interview 6 Sep 2026 · in the article since 13 Nov 2026 Contribution — Ziyu Yao 11 statements added to this article
  3. 3 HY Hao Yan, lead author Contributor · interview 8 Sep 2026 · in the article since 13 Nov 2026 Contribution — Hao Yan 15 statements added to this article
  4. 4 I icml.cc Third-party reporting · icml.cc ICML Interpreting Code Correctness in Language Models through Activation Steering See the source

Article history

  1. Update 26 Nov 2026, 18:10

    This article was updated to reflect revised text and images.

  2. Published 13 Nov 2026, 14:15
    Assembled by the Primary desk from 2 sources · 2 contributors · 31 cited sentences
  3. Hao Yan, lead author 15 statements added 67 days before publication
    1. Go to the sentence: To identify the specific components responsible for vulnerable code, Yan and Yao created CodeSec-Pairs, a dataset comprising 9,342 contrastive pairs of safe and vulnerable Python programs sampled from the open-source model Llama-3.1-8B-Instruct.
    2. Go to the sentence: Yan told Primary that “CodeSec-Pairs is built for safe-versus-vulnerable pairs, not for functional correctness.”
    3. Go to the sentence: At the same time, the double-steering technique improved the functional correctness of the generated Python programs by an average of 7.5 percent over baseline outputs.
    4. Go to the sentence: The authors reported that this dual intervention outperformed alternative single-direction steering variants, standard prompt-engineering approaches, and supervised fine-tuning baselines on the same evaluation benchmarks.
    5. Go to the sentence: Yan stated that the magnitude of improvement depended heavily on how consistent the underlying security fixes were.
    6. Go to the sentence: When a flaw has a uniform solution, such as escaping user text for cross-site scripting or selecting a safe loader function for deserialization, steering vectors find clear leverage.
    7. Go to the sentence: In contrast, for path traversal flaws, where 64 percent of dataset pairs lacked a dominant fix pattern, steering proved less effective on its own.
    8. Go to the sentence: Yan noted that combining steering with prompt hints offered supplementary benefits on those diffuse vulnerability classes.
    9. Go to the sentence: On absolute functional metrics across SecCodePLT benchmarks, DuoSteer increased correctness on unsafe deserialization from 58.8 percent to 94.1 percent, on certificate validation from 41.2 percent to 60.8 percent, and on code injection from 25.5 percent to 27.5 percent in Llama-3.1-8B-Instruct.
    10. Go to the sentence: While correctness on path traversal and cross-site scripting finished below the unsteered baseline, it remained well above single-direction safety steering.
    11. Go to the sentence: When evaluated on benchmark unit tests, pass rates climbed from 62.7 percent to 88.2 percent on deserialization and from 43.1 percent to 51.0 percent on code injection.
    12. Go to the sentence: Regarding computational overhead, Yan explained that DuoSteer adds a fixed vector to between 16 and 128 attention heads out of the model’s 1,024 total heads per generated token.
    13. Go to the sentence: Because this operation requires no extra model passes, no parameter updates, and no gradient storage during deployment, its inference latency is negligible compared to standard generation.
    14. Go to the sentence: Yan also emphasized that attention head locations and steering vectors are specific to each distinct model architecture and cannot be transferred directly across models.
    15. Go to the sentence: In addition, the experiments examined isolated Python functions, leaving multi-file repositories and memory-safety vulnerabilities in languages like C and C++ untested.
  4. Ziyu Yao, co-author 11 statements added 69 days before publication
    1. Go to the sentence: Rather than retraining an entire system or attempting to catch errors after code is written, the method, named DuoSteer by the authors, applies simultaneous adjustments at inference time to two distinct internal properties: code security and functional correctness.
    2. Go to the sentence: In neural representations, conceptual relationships often align along specific geometric vectors.
    3. Go to the sentence: Ziyu Yao, a co-author of the paper, explained that just as the linguistic difference between words like king and queen aligns with a gender vector, code properties behave similarly.
    4. Go to the sentence: Yao said in response to questions from Primary that the concepts of security and functional correctness occupy separate trajectories within the network, noting that DuoSteer works by pulling an artificial intelligence system toward both goals simultaneously.
    5. Go to the sentence: As Yao told Primary, the researchers first applied security steering, collected verified secure outputs, and then contrasted correct and incorrect functional executions on those outputs to isolate the functional correctness vector.
    6. Go to the sentence: Applying separate steering adjustments to the distinct sets of attention heads responsible for each property allowed the system to suppress vulnerabilities without breaking functional logic.
    7. Go to the sentence: Yao told Primary that the two diagnostic methods produced completely divergent results, with a correlation between their head rankings that was essentially zero across every tested vulnerability type.
    8. Go to the sentence: When researchers steered the attention heads highlighted as top candidates by passive probes, the vulnerability rate barely moved across three of the five tested vulnerability categories, whereas steering the heads identified through knockouts successfully reduced vulnerabilities.
    9. Go to the sentence: For four out of five tested vulnerability classes in Llama-3.1-8B-Instruct, the distinction between safe and vulnerable code peaked in middle layers 9 to 11 of the 32 total layers.
    10. Go to the sentence: In contrast, for improper certificate validation, where code fails to validate a server security certificate, the strongest signal appeared at the final layer.
    11. Go to the sentence: Because each vulnerability type involved its own distinct set of causally relevant attention heads, the steering vectors had to be calibrated separately for each flaw category.