How AgentQ reads library source, writes taint specifications and reaches 86% accuracy with GRPO, DAPO and mixed-temperature decoding.
Pratik Pagar, ML/AI Engineer at Farion
One of the hardest problems in application security is following data through large software systems. Taint analysis tracks untrusted data from a source, such as an HTTP request, to a sink, such as a SQL query. It is a fundamental building block of vulnerability detection. Precise data flow engines require substantial engineering; open-source tools exist, but following complex flows across applications and dependencies remains difficult.
We often discuss compiler-level analysis and Static Single Assignment (SSA). Here we look at a problem that gets less attention but matters just as much: what happens when data crosses a library boundary?
The problem with external libraries
Data flow analysis works well while the relevant code is available to the analyzer. It gets harder when data goes into an external library and comes back out.
Semgrep propagates taint from arguments to return values for opaque function calls by default. CodeQL uses extensible models for library behavior. Both face the same underlying problem: the analyzer needs accurate semantics for each dependency and version. The IRIS paper explored LLM-generated taint specifications as one way to address missing models.
Consider two calls in a Go handler. gjson.Get(body, "user.id") returns part of its input. Concatenate that result into a SQL query and you risk injection. bluemonday.UGCPolicy().Sanitize(body) sanitizes input for HTML. Treat both as propagators and you risk a false positive at an HTML sink; treat both as sanitizers and you miss the SQL injection.
And this is an easy case. A library might write tainted input to a cache or package-level variable, then return it from another function that receives no tainted arguments. For the analyzer, that function introduces a new source.
So we asked: can an agent read library source the way a security reviewer does, and write a taint specification for each call?
AgentQ: an agent that reads library code
Farion uses language-specific analyzers to build code property graphs. Our data flow engine processes those graphs and passes the results to downstream security scanners.
To solve this problem, we built a microservice that we call AgentQ. It builds a separate knowledge database of library behavior. It reads the source code of a specific library version and produces specifications for our analyzer to use at dependency boundaries. Each specification has one of five verdicts:
| Verdict | Meaning |
|---|---|
propagates | Taint reaches a return value, output parameter or readable state. |
drops | Tainted input produces no tainted output visible to the caller. |
sanitizes | Input is made safe for a specific security context, such as HTML. |
new_source | A call introduces tainted data not derived from its arguments. |
unknown | Available evidence is insufficient for a reliable verdict. |
AgentQ supplies knowledge. Applying it to real program flows is the job of the analysis engine.
Can a language model answer these questions on its own?
A model may recognize popular libraries, but its training data cannot reflect every version. Like a reviewer, it must read the exact source and collect evidence. We built an agent harness that provides matching library code in an isolated sandbox. The agent can search and read it, but cannot execute it or access the web.
We started with a few thousand labeled verdicts across dozens of Go packages: frameworks, parsers, SQL builders, database drivers, sanitizers and caches. Before training, we expanded the dataset to hundreds of packages across Go, Java and Python, divided into training, validation and test sets.
The first harness reached 52% accuracy, meaning the share of library-call verdicts matching our labels. We examined its trajectories: tool calls, retrieved code and verdicts. Fixing issues in the harness, tools and system prompt raised validation accuracy to 74%, without training the model.
Now the remaining errors were different: the agent found the right code but drew the wrong conclusion. We needed to improve its reasoning.
Why reinforcement learning?
Supervised fine-tuning (SFT) was an option, but our labels described correct outcomes, not complete trajectories. In an early experiment, the model copied demonstration patterns that did not transfer well to differently structured libraries.
We chose reinforcement learning (RL), which lets us score outcomes without prescribing every reasoning step or tool call.
We used Group Relative Policy Optimization (GRPO), introduced in DeepSeekMath (Shao et al., 2024). Unlike PPO, which typically needs a separate value model, GRPO compares several trajectories for the same prompt. Those scoring above the group average are reinforced; those below it are discouraged.
The reward scored verdict correctness, tool use, excessive tool calls and output format. Writing it was one of the hardest parts: the model optimizes what we measure, not what we intend. An early check penalized tool outputs containing "error". Go code is full of that word, so we punished the agent for reading normal code. We also had to weight rare verdicts such as sanitizers, or the model tended to ignore them.
When training stopped improving
Our first GRPO run made the model worse. We adopted two techniques from DAPO (Yu et al., 2025): Clip-Higher, giving useful but unlikely tokens more room, and token-level loss, changing how long trajectories contribute to training.
Validation accuracy reached 82%, then stopped. More epochs, different KL penalties, temperatures and training samples did not help.
We examined the training trajectories again. For each prompt, the model generated 16 trajectories. In most groups, all 16 returned the same verdict and reward, either all right or all wrong. When rewards are identical, there is no relative learning signal. Much of our compute went into groups that could not improve the model. DAPO also proposes dynamic sampling to filter out such groups. Our experiment focused on increasing diversity within them.
We masked system prompts and tool results out of the training loss because the model did not generate them. Tool calls needed special care: too much policy drift could break the interface the agent used to inspect source. A KL penalty helped limit that drift.
We needed more variation, but higher sampling temperatures made tool calls and structured verdicts unstable. So we tried mixed-temperature decoding: 1.0 for reasoning, 0.05 for tool calls and 0.3 for verdicts.
This allowed more exploration while keeping tool use predictable.
Validation accuracy reached 87%, with one unparseable verdict on the validation set rather than four or five. On the test set, accuracy was 86%.
What we learned
Reading the exact source matters. A model answering from memory may rely on outdated library behavior. AgentQ reads the exact version that a project uses, and every verdict comes with its trajectory: the code the agent read and the reasoning it gave. A security reviewer can check that evidence, which matters when an audit asks why a finding was raised or dismissed.
No fixed default is right for every library. AgentQ gives Farion's data flow engine a separate answer for each call, instead of one guess for every dependency.
In our RL experiments, the bottleneck was the learning signal, not the algorithm. The DAPO authors put it in one line: "A zero advantage results in zero policy gradients." More compute does not help when the samples carry no signal. Making the samples differ does.
Credit assignment is still open. Our reward already scores steps on the way: tool use, the number of tool calls and the output format. But all of these terms add up to one scalar for the whole trajectory, so the model cannot see which search or which sentence of reasoning made the difference.
The research offers directions. Process supervision, which rewards each reasoning step, outperformed outcome supervision on math problems. But DeepSeek tried process reward models for R1 and listed them as an unsuccessful attempt: a "fine-grain step" is hard to define, the correctness of an intermediate step is hard to judge, and a learned reward model "inevitably leads to reward hacking". For an agent that reads code, what a correct intermediate step looks like is still an open question.
With AgentQ, our data flow engine can use evidence about what happens at a library boundary instead of relying on a fixed assumption. AgentQ supplies that knowledge, while another Farion component combines the resulting data flows to identify vulnerabilities across the application. We'll discuss that part of the architecture in a future article.
