PPDL: LLM-Based Flows as Probabilistic Programs
The project
Showcase
Louis Mandel, Guillaume Baudart, Mandana Vaziri and Martin Hirzel
arXiv, 2026Machine learning
- article
- alltt
- mathpartir
- pgfplots
- listings
Compare with TeX's PDFOriginalSource
CC BY 4.0, published at arxiv.org. “PPDL: LLM-Based Flows as Probabilistic Programs” by Louis Mandel, Guillaume Baudart, Mandana Vaziri, Martin Hirzel, arXiv:2608.05234v1. Licensed under CC BY 4.0. Typeset here by reflowtex from the authors' source.
PPDL: LLM-Based Flows as Probabilistic Programs
Louis Mandel1 Guillaume Baudart2 Mandana Vaziri1 Martin Hirzel1
Abstract
Building reliable applications that leverage large language models (LLMs) remains a significant challenge. While LLMs offer impressive capabilities across diverse tasks, their outputs often lack accuracy and provide no clear measure of confidence. This uncertainty compounds in flows of multiple calls to LLMs and other tools, making it difficult for developers and end-users to trust the results. This paper introduces a probabilistic language for programming LLM-based flows. It enables developers to quantify and propagate uncertainty throughout the application’s flow, and experiment with different inference scaling techniques without adding a single line of code beyond the flow’s logic. We present an experimental study to demonstrate this capability, and a case study building a theorem proving agent for the Rocq theorem prover.
1. Introduction
While a single call to a large language model (LLM) can perform remarkably well for some tasks, other tasks require flows of multiple calls to LLMs and other tools (Jimenez et al., 2024). But while such LLM-based flows may improve accuracy, unfortunately, they also exacerbate uncertainty. Because each step depends on previous uncertain outputs, uncertainty compounds along the trace of a flow’s execution. This makes it difficult for users to assess the correctness of an answer, leaving them wondering how certain it is and what other answers are likely.
Figure 1: Executing LLM-based flows with or without probabilistic programming. Each circle represents an execution state, with darker shades indicating higher normalized probability.
Several recent solutions for improving LLM flow accuracy use inference scaling, which scales up the number of LLM inference calls or tokens at test time (Chen et al., 2023; Cobbe et al., 2021; Wang et al., 2023; Yao et al., 2023a;b). The idea is to try the same task several times, either independently or with feedback between attempts, hoping that one of the outputs is correct. Inference scaling usually leverages constraints to refine or select outputs, including soft constraints from models and hard constraints from rule-based tools. Since it explores a distribution of outputs and attempts to shape that distribution via constraints, it could be viewed as a form of probabilistic programming (Gordon et al., 2014). But in practice, it tends to be more ad hoc. While inference scaling could save cost by allocating more resources to better execution traces, that would require a principled way to track multiple partial traces along with their likelihoods. However, current inference scaling implementations are tightly interwoven with the program, increasing complexity and hindering the exploration of alternative paradigms. Furthermore, although in theory inference scaling could help users assess answer quality (since it deals in distributions), in practice it is rarely principled enough to deliver that benefit.
To obtain more accurate results from LLM-based flows while also giving users visibility into their uncertainty, we aim to make inference scaling more principled by incorporating it into a programming language. We introduce PPDL, the first probabilistic programming language for LLM-based flows. In general, Probabilistic programming languages (Gordon et al., 2014; Carpenter et al., 2017; Goodman et al., 2008; Bingham et al., 2019) decouple the search over a distribution of traces from the core program logic, but they are notoriously hard to use and are not applied to LLM-based flows. Prompt programming languages (Lundberg et al., 2022; Khattab et al., 2024; Zheng et al., 2024; Mell et al., 2025) make it easy to compose flows of LLM and tool calls, but do not help with tracking uncertainty. And while they enable developers to explicitly build ad hoc inference scaling workflows, such close coupling between the search and the core logic is complicated and inflexible.
PPDL’s goal is to bring these two paradigms together in a single framework. PPDL is designed for developers and researchers who build multi-step LLM or agentic workflows, including prompt-language users, agent framework developers, and researchers experimenting with inference scaling. PPDL lets users specify the core logic of their program in a high-level prompting language which already provides one of the two core constructs of probabilistic languages, namely sample in the form of an LLM call. It extends this language with the second of the two core constructs of probabilistic languages, namely factor. A factor updates the probability of the current execution trace based on user-specified soft or hard constraints.
Flow specifications in PPDL require no explicit inference scaling loops, as the runtime takes care of exploring a distribution of possible traces (see Figure 1). Thus, PPDL effectively decouples inference scaling from the core program logic, providing a suite of plug-and-play probabilistic inference engines: simple majority voting, importance sampling, and particle filtering (aka. Sequential Monte Carlo or SMC). Each particle represents a possible trace through the program, which might involve multiple LLM and tool calls. Unlike traditional prompting languages that return a single output, PPDL returns a distribution of outputs. Users can then inspect that distribution to assess uncertainty, or pick a single output, such as the one with the highest probability score.
Besides prompts, sample (LLM calls), and factor, PPDL includes constructs for variables, control structures (loops, conditionals, error handling), functions, file imports, and tool calls. It allows users to write a flow once and then experiment with various inference scaling engines without writing an additional line of code. This paper formalizes a semantics for PPDL that clarifies its behavior as both a prompting language and a probabilistic language, and the resulting distribution of traces and output values. Furthermore, this paper describes an implementation with parallelization both within a single execution trace and across multiple in-flight partial traces using functional data structures. The empirical results show the versatility of PPDL as a framework for experimenting with different inference scaling algorithms across multiple widely used benchmarks, as well as a case study where it is used to implement a theorem proving agent for the Rocq theorem prover (Rocq Prover Team).
This paper makes the following novel contributions:
1. PPDL, the first probabilistic prompt programming language for flows of LLM and tool calls.
2. A semantics that formalizes the interplay between prompt-based sample and probabilistic factor.
3. Results with different probabilistic inference engines across different LLMs and benchmarks.
4. A case study building a theorem proving agent for the Rocq theorem prover.
PPDL is open-source and distributed with PDL: https://github.com/IBM/prompt-declaration-language/tree/icml-26.
Conflict of Interest Disclosure. All the authors, except Guillaume Baudart, are employed by IBM, which leads the development of the Granite models, which were among the ones evaluated in this paper.
2. Overview
Prompt programming. PPDL is based on PDL (Vaziri et al., 2024), a declarative approach to prompt programming that combines human readability with ease of execution. PDL programs represent the composition of calls to LLMs and tools, abstracting away the plumbing necessary for such compositions. PDL is based on the premise that interactions with an LLM are mainly for the purpose of generating data. Users specify the shape of data to be generated in YAML, which makes it easy to see properly formatted prompts. PDL adds enough scripting to allow specifying entire flows. Code blocks allow users to compose LLM calls with arbitrary code written in Python, Jinja2, or Shell. PDL enables implicit accumulation of the context of messages, freeing users from such concerns, and provides type checking and constrained decoding to enforce the shape of LLM outputs.
Consider the example in Figure 2, which illustrates a simple flow: we first ask a model to generate a plan in natural language for how to generate code for a problem, then we chain that with another model call to generate code while taking the plan into account. Lines 1–5 define some variables for use in the rest of the program. Line 6 declares the shape of data to be produced as a lastOf, which means a sequence of blocks whose result is that of the last block in the sequence. Lines 7–20 are a list of blocks comprising the body of lastOf. Lines 7–9 show a prompt asking for an English plan for a code generation problem. Line 10 shows a declarative model call. It provides the id of the model to call from the variable llm defined in Line 2 (PDL is based on LiteLLM, so this is a LiteLLM id for a watsonX model). A PDL program implicitly accumulates the context in the background, so the input to this model call is everything that appeared before. In this case, the input to the model is the prompt on Lines 7–9. Next, we formulate a prompt to generate code (Lines 11–14). This is followed by another model call on Lines 15–19 for code generation. Its input includes all previous prompts and the response of the first model call. The output is parsed using the regular expression on Line 17, which defines the code capture group. On Line 18, a type specification enforces the shape of the output to be a JSON object with a code field. Line 19 defines the variable solution to hold the response of the LLM. Finally, Line 20 contains a Jinja expression that accesses the content of solution.code. Since the top-level block is a lastOf, the output of the program is the result of this last block. The left column of Table 1 shows some possible outputs of the program, since LLM responses are not deterministic.
1 d e f s : 2 l l m : w a t s o n x / m e t a - l l a m a / l l a m a - 4 - m a v e r i c k - . . . 3 p r o b l e m _ s t a t e m e n t : | 4 W r i t e a f u n c t i o n t o f i n d n t h c e n t e r e d h e x a g o n a l n u m b e r . 5 a s s e r t c e n t e r e d _ h e x a g o n a l _ n u m b e r ( 1 0 ) = = 2 7 1 6 l a s t O f : 7 - > 8 G e n e r a t e a n E n g l i s h p l a n f o r h o w t o g e n e r a t e c o d e f o r 9 t h e f o l l o w i n g p r o b l e m : $ { p r o b l e m _ s t a t e m e n t } 10 - m o d e l : $ { l l m } 11 - > 12 G e n e r a t e a c o m p l e t e e x e c u t a b l e P y t h o n f u n c t i o n 13 d e f i n i t i o n c o r r e s p o n d i n g t o t h e a b o v e p l a n a n d p r o b l e m . 14 G e n e r a t e o n l y a s i n g l e f u n c t i o n d e f i n i t i o n . 15 - m o d e l : $ { l l m } 16 p a r s e r : 17 r e g e x : ( . | \ n ) * ‘ ‘ ‘ p y t h o n \ n ( ? P < c o d e > ( . | \ n ) * ? ) ‘ ‘ ‘ ( . | \ n ) * 18 s p e c : { c o d e : s t r i n g } 19 d e f : s o l u t i o n 20 - $ { s o l u t i o n . c o d e | d e f a u l t ( ” ” ) }
Figure 2: PDL program generating a Python function.
1 d e f s : 2 l l m : w a t s o n x / m e t a - l l a m a / l l a m a - 4 - m a v e r i c k - . . . 3 p r o b l e m _ s t a t e m e n t : | 4 W r i t e a f u n c t i o n t o f i n d n t h c e n t e r e d h e x a g o n a l n u m b e r . 5 a s s e r t c e n t e r e d _ h e x a g o n a l _ n u m b e r ( 1 0 ) = = 2 7 1 6 u t i l s : 7 i m p o r t : u t i l s . p d l 8 l a s t O f : 9 - > 10 G e n e r a t e a n E n g l i s h p l a n f o r h o w t o g e n e r a t e c o d e f o r 11 t h e f o l l o w i n g p r o b l e m : $ { p r o b l e m _ s t a t e m e n t } 12 - m o d e l : $ { l l m } 13 d e f : p l a n 14 - d e f s : 15 c o n s t r a i n t : | 16 T h i s p l a n f o r t h e f o l l o w i n g p r o b l e m i s c o r r e c t . 17 $ { p r o b l e m _ s t a t e m e n t } 18 f a c t o r : $ { u t i l s . l l m _ j u d g e ( l l m , p l a n , c o n s t r a i n t ) } 19 - > 20 G e n e r a t e a c o m p l e t e e x e c u t a b l e P y t h o n f u n c t i o n 21 d e f i n i t i o n c o r r e s p o n d i n g t o t h e a b o v e p l a n a n d p r o b l e m . 22 G e n e r a t e o n l y a s i n g l e f u n c t i o n d e f i n i t i o n . 23 - m o d e l : $ { l l m } 24 p a r s e r : 25 r e g e x : ( . | \ n ) * ‘ ‘ ‘ p y t h o n \ n ( ? P < c o d e > ( . | \ n ) * ? ) ‘ ‘ ‘ ( . | \ n ) * 26 s p e c : { c o d e : s t r i n g } 27 d e f : s o l u t i o n 28 - f a c t o r : $ { u t i l s . s c o r e _ e r r o r s _ a n d _ w a r n i n g s ( s o l u t i o n ) } 29 - $ { s o l u t i o n . c o d e | d e f a u l t ( ” ” ) }
Figure 3: PPDL program adding constraints with factor.
Table 1: (Left) Possible outputs of the PDL code from Figure 2; (Right) Posterior probability and particle count added by Figure 3.
Output Probability Count d e f c e n t e r e d _ h e x a g o n a l _ n u m b e r ( n ) : r e t u r n 1 + 3 * n * ( n + 1 ) 0.00005 3 d e f c e n t e r e d _ h e x a g o n a l _ n u m b e r ( n ) : r e t u r n 1 + 3 * n * ( n - 1 ) 0.99988 1 d e f c e n t e r e d _ h e x a g o n a l _ n u m b e r ( n ) : r e t u r n 1 + 6 * ( n * ( n + 1 ) ) / / 2 0.00007 1
Probabilistic prompt programming. PPDL extends PDL with a single additional primitive, factor, but fundamentally changes the execution model by turning the program into a distribution over traces. In PPDL, the user can use factor to score executions. The program is then bootstrapped into a probabilistic framework that uses those scores in various algorithms. The output of PPDL is a distribution of results, from which the user can sample the answer with the highest probability, providing a greater likelihood of correctness.
Figure 3 shows the same program as Figure 2, but with added constraints. Lines 6–7 import utils, a library with utility functions not shown in this figure. Lines 14–18 score the plan that was generated using an LLM-as-a-judge (Zheng et al., 2023). The function utils.llm_judge takes a model name, a response, and a constraint, and checks whether the response meets the constraint. It is an LLM call that returns true or false, and we use the log probabilities output by the LLM to compute a score according to the following formula:
score = log exp(lpt) exp(lpt)+exp(lpf)
where lpt and lpf are the log probabilities for true and false, respectively. Line 28 shows a rule-based constraint, where we compute a score based on the errors and warnings from the flake8 linter.
Each execution of the program now generates an output and a score that reflect the quality of the corresponding execution with respect to the user constraints introduced by factor. The PPDL runtime then performs probabilistic inference, which leverages these scores to estimate the posterior distribution of possible outputs. Probabilistic inference is, in general, intractable, and the distributions computed by LLMs operate over enormous spaces. PPDL thus relies on Monte Carlo approximate inference algorithms that launch a series of independent executions, called particles, to estimate the posterior distribution. For example, using 5 particles, we obtain the distribution of solutions shown in Table 1. The solution with high probability is correct, while the other two are incorrect. Three of the five particles found the first solution, so majority voting would have yielded a wrong solution. Appendix A shows some step-by-step executions of the program.
The advantage of constraints is that they attach probabilities to each response, allowing PPDL to return a correct response even if that response is not part of the majority. In this example, we used importance sampling, but we could have used the same program and selected majority voting or Sequential Monte Carlo. PPDL allows the user to write the logic of the flow once, and experiment with different inference scaling approaches without needing additional code. Appendix B presents alternative implementations of Figures 2 and 3 in other frameworks to illustrate the refactoring required when switching inference scaling algorithms.
Inference scaling approaches depend on constraints to steer execution traces and select solutions. Constraints can be hard (e.g., failing tests) or soft (e.g., being scored on a scale), cheap (e.g., checking syntax) or expensive (e.g., calling a large model). Sometimes constraints are sound, sometimes complete, but even when neither sound nor complete, they can improve predictive performance. Some inference scaling literature (Cobbe et al., 2021; Stroebl et al., 2026) refers to the source of constraints as “verifiers,” but we avoid that terminology because it misleadingly implies soundness. Other literature, inspired by reinforcement learning, refers to constraints as rewards and distinguishes process rewards (in the middle of an execution trace) from outcome rewards (at the end of a completed trace). Constraints can come from models, which can be either fine-tuned for this task (e.g., process reward models, PRMs) or prompted for this purpose (Zheng et al., 2023). PPDL supports all of the above forms of constraints via the probabilistic factor as a single orthogonal language construct.
3. Language and Approach
This section presents how PPDL programs execute, formalizing their behavior through a probabilistic semantics.
Overview. As shown in Figure 1, PPDL lets users express an LLM-based flow as a program with factors (top left), then explores traces of that program to obtain a distribution of output values (bottom left). This section formalizes this intuition via a semantics of the form p/S λv.Pr(v), where p is a program, S is its environment state, ⇝ means reduces to, and λv.Pr(v) denotes a categorical probability distribution over output values v. To define such a semantics over all traces, we first define a semantics for a single trace, which has the form p/S ⇒∗ v/S′. We refer to the single-trace semantics as a weighted sampler, where the weights come from factors and the sampling happens via LLM model calls. The weighted sampler is defined using reduction rules of the form p/S ⇒ p_or_v/S′. Each reduction rule transforms its left-hand side (program p and environment S) into its right-hand side (the remainder of the program at the next factor or a final value v, with updated environment S′). The reduction ⇒∗ is the transitive closure of ⇒ and continues until it produces a value.
During execution, the environment S keeps track of two special variables: S[pdl_context] accumulates messages, and S[pdl_score] is the trace likelihood. LLM calls introduce randomness: each model call samples a response from the distribution defined by an LLM given the current pdl_context, resulting in a new message appended to pdl_context. Each factor increments pdl_score by a value provided as a parameter. A hard constraint corresponds to a factor with parameter −∞ (probability 0 in log space). As in classic probabilistic programming languages (Bingham et al., 2019; Carpenter et al., 2017), we can assume that a value was sampled from a distribution using a factor whose parameter is the log-density of the distribution at that point. The value of pdl_score thus represents how well the trace satisfies the user constraints.
Section 3.1 formalizes the weighted sampler by defining the syntax and semantics of core PPDL blocks (see Appendix C for the remaining blocks). The ideal semantics (⇝) uses an infinite weighted sum over all possible traces (⇒∗). Section 3.2 describes the probabilistic inference engines, each of which computes a finite approximation of the ideal semantics. Both the ideal semantics and the approximate inference engines rely on the weighted sampler. Section 3.3 describes the parallelized implementation of the weighted sampler and the inference engines.
3.1. Weighted Sampler
pdl ::= { defs:{x:pdl, . . . ,x:pdl}, body, parser:parser, contribute:contribute, def:x } body ::= data:expr | code:pdl,lang:string | model:expr,input:pdl | if:expr,then:pdl,else:pdl | sequence:[pdl, . . . ,pdl],join:join | while:expr,repeat:pdl,join:join | function:types,return:pdl | call:expr,args:expr | factor:expr expr ::= null | bool | number | string | ${jinja_expr} | [expr, . . . ,expr] | {x:expr, . . . ,x:expr}
Figure 4: Syntax of PPDL (using the flow-style of YAML).
defs/S defs − → {}/S1 block_body/S1 → v/S2 parser, v parse − → v′ S2, v′, contribute contrib − → S3 S′ = S3[x ← v′] {defs:defs,block_body,parser:parser,contribute:contribute,def:x}/S ⇒ v′/S′ S ⊢ model ⇓ m S ⊢ input ⇓ i sample(m, i) = v model:model,input:input/S → v/S S ⊢ e ⇓ w S′ = S[pdl_score ← S[pdl_score] + w] factor:e/S → data:””/S′ S ⊢ f ⇓ function:t,return:p, scope:Sf S ⊢ args ⇓ args′ args′ ∈ tp/Sf[pdl_context ← S[pdl_context], pdl_score ← S[pdl_score]] + args′ ⇒ v/S′fS′ = S[pdl_context ← S′f[pdl_context], pdl_score ← S′f[pdl_score]] call:f,args:args/S → v/S′
Figure 5: Key reduction rules for blocks (p/S ⇒ p_or_v/S′) and block-bodies (b/S → b_or_v/S′). The reduction S ⊢ e ⇓ v represents the evaluation of an expression e into a value v in the environment S. The full semantics is provided in Appendix C.
Figure 4 presents the syntax of a simplified kernel of PPDL, showing its context-free grammar in Backus-Naur Form. A program is a block comprising a set of variable definitions, the block body (i.e., the instruction to evaluate), a parser to extract the result from the return value of the body, a flag indicating whether the result contributes to the context, and the name of the variable in which to store this result. The body of a block can be an expression (data), code for a tool call, an LLM call with its input, a conditional, a sequence of blocks with a join operator to gather result values, a loop with a join operator to gather the results of each iteration, a function definition, a function call, or a factor statement to update the score. The examples from Section 2 can be compiled into this kernel. For instance, blocks without an explicit defs clause can be compiled to use an empty defs, and a model block without an input clause can be compiled to use pdl_context as input.
The top rule of Figure 5 is the main rule defining the weighted sampler reduction p/S ⇒ p_or_v/S′. The notation for the rules in this paper places premises (sub-steps) above a horizontal line and conclusions (the reduction being defined) below the line. The premises for evaluating a block begin by evaluating the variable definitions, then running the block body to produce a value v, parsing v into a new value v′, and finally contributing v′ to the background context and adding it to the environment. Contribution to the background context is performed by adding a message to the sequence in pdl_context (we omit the role in the semantics for simplicity):
ctx = S[pdl_context] + [{content:v}] S′ = S[pdl_context ← ctx] S, v, [pdl_context] contrib − → S′
The rest of Figure 5 shows the key block-body reduction rules. The model block evaluates the model name and input expressions to get an actual model name m and a sequence of messages i, then samples the LLM corresponding to m conditioned on i to obtain the output. The factor block computes a score w and increments the pdl_score variable by this value. It rewrites into a block that returns the empty string. The rule for a function call illustrates the handling of the special variables pdl_context and pdl_score. As in functional programming languages, it first retrieves the function definition along with its local environment, evaluates the arguments, checks that they are well-typed, then evaluates the function body in the local environment to compute the returned value. A key property of PPDL is that pdl_context and pdl_score are propagated through function calls, allowing accumulation to continue.
Now that we have a weighted sampler, we can define the ideal semantics of a PPDL program as an infinite number of executions of the sampler (N → ∞) and normalize the weights to obtain a categorical distribution:
{p/S ⇒∗ vi/Si}1≤i≤N wi = exp(S′i[pdl_score])1≤i≤N W = 1≤i≤N wi p/S λU. 1≤i≤N(wi/W) × δvi(U)
The premise {p/S ⇒∗ vi/Si}1≤i≤N denotes a collection of N executions of the program p starting from the same initial environment S. Each execution reduces p to a final value vi and environment Si. Each Si contains the variable pdl_score, which stores the unnormalized weight (in log space) accumulated along the corresponding execution trace. The sum W normalizes the score of each result vi. The final result is a categorical distribution that, given a set of values U, returns its probability (where δvi(U) is the Dirac distribution that returns 1 when vi ∈ U).
3.2. Inference Engines
The ideal semantics are intractable as N → ∞, but probabilistic programming inference algorithms provide ways to approximate them. For example, if N is bounded, the rule defining the semantics corresponds to the Importance Sampling (IS) algorithm. Each reduction p/S ⇒∗ vi/Si is a particle computing a value vi with its score Si[pdl_score]. Similarly, majority voting uses the same rule with uniform weights, ignoring Si[pdl_score].
We can also use our weighted sampler to describe the Sequential Monte Carlo (SMC) algorithm (Del Moral et al., 2006). With SMC, during execution, particles with a low score drop their current execution path and restart from the state of a particle with a higher score. The state selection is made by sampling from the distribution of program states at each resampling point. In PPDL, the resampling points correspond to the factor blocks (i.e., when the reduction ⇒ returns a program block p instead of a value v).
The SMC algorithm is formalized as follows:
δp,S ⇝∗ Dv,S′ p/S π1(Dv,S′) pi/Si ⇒ p′i/S′i | (pi, Si) = sample(Dp,S)1≤i≤N wi = exp(S′i[pdl_score])1≤i≤N W = 1≤i≤N wi Dp,S ⇝ λU. 1≤i≤N(wi/W) × δp′i,S′i[pdl_score←0](U)
Starting from a program p and environment S, we turn this initial state into a Dirac distribution (δp,S) and then apply the reduction Dp,S ⇝ Dp′,S′, which rewrites a distribution of program states (pairs of program and environment) into a new distribution. When all programs in the distribution reduce to values (Dv,S′), the result is the pushforward of the distribution across the first projection (π1), yielding the distribution of return values alone.
The reduction Dp,S ⇝ Dp′,S′ samples N program/environment pairs from Dp,S and applies the weighted sampler ⇒ to compute the next distribution.
3.3. Parallel Execution
PPDL is an interpreted language. Its implementation directly follows the semantics. Both the implementation of the inference engine and of the weighted sampler are parallelized.
Bayesian inference algorithms such as IS and SMC are inherently parallel, since they rely on independent executions of particles. With IS, full traces can be executed in parallel. SMC introduces a synchronization point at each resampling step, when the distribution of intermediate program states is built and sampled. The PPDL interpreter implements this parallelism using multi-threading.
Within the execution of a particle, the PPDL interpreter parallelizes independent model calls using futures (Halstead, 1985). Model calls return a promise of a response rather than blocking. When an expression is evaluated, the interpreter traverses the relevant data structures to await the responses of only those model calls on which the expression depends. To limit dependencies, the data structures created by PPDL, especially pdl_context, are lazy (Okasaki, 1998), ensuring that only the accessed cell of an array or field of an object is awaited.
4. Evaluation
Table 2: Accuracy comparison across benchmarks, models, and inference algorithms. IS@1 is the baseline (single execution), Maj. Voting (Majority Voting), IS (Importance Sampling), and SMC (Sequential Monte Carlo) use 5 particles each, and pass@k represents the oracle upper bound. Bold indicates best performance among inference algorithms. All results show mean ± standard deviation over 3 runs.
model IS@1 Maj. Voting IS SMC pass@k GSM8k granite4-small 83.8% ± 0.3 90.4% ± 0.9 93.7% ± 0.5 92.3% ± 0.3 96.1% ± 0.3 granite4-micro 79.5% ± 0.9 87.1% ± 1.6 87.8% ± 0.4 84.2% ± 0.6 93.7% ± 0.1 llama4-scout 93.9% ± 0.2 94.5% ± 0.3 94.4% ± 0.3 94.6% ± 0.3 95.5% ± 0.2 llama4-maverick 95.3% ± 0.2 95.7% ± 0.4 95.4% ± 0.3 95.3% ± 0.3 96.7% ± 0.3 gpt-oss-120b 86.9% ± 0.3 90.4% ± 0.8 92.2% ± 0.3 90.8% ± 0.0 95.1% ± 0.1 gpt-oss-20b 90.2% ± 1.2 93.1% ± 0.5 92.7% ± 0.4 91.9% ± 0.8 95.5% ± 0.2 Math500 granite4-small 60.7% ± 0.4 62.1% ± 0.6 64.0% ± 1.1 65.5% ± 1.7 75.7% ± 0.3 granite4-micro 47.4% ± 0.6 47.7% ± 1.2 52.5% ± 1.1 51.1% ± 0.7 66.5% ± 0.5 llama4-scout 66.3% ± 0.1 65.7% ± 0.5 67.3% ± 0.4 67.5% ± 0.6 71.9% ± 0.3 llama4-maverick 69.9% ± 0.3 69.7% ± 0.6 71.5% ± 0.9 70.1% ± 0.5 74.7% ± 0.6 gpt-oss-120b 74.2% ± 0.2 73.8% ± 1.1 74.8% ± 1.0 74.5% ± 0.3 77.9% ± 0.3 gpt-oss-20b 74.1% ± 0.1 74.0% ± 1.1 75.7% ± 0.5 74.9% ± 0.4 79.0% ± 0.2 MBPP granite4-small 69.7% ± 1.9 69.7% ± 2.9 80.5% ± 2.1 80.2% ± 2.0 92.0% ± 1.2 granite4-micro 71.9% ± 1.0 72.9% ± 2.5 75.1% ± 2.6 74.8% ± 0.3 89.5% ± 1.8 llama4-scout 82.5% ± 0.9 81.7% ± 2.0 86.1% ± 2.1 85.4% ± 1.6 92.0% ± 1.6 llama4-maverick 90.3% ± 0.5 90.4% ± 2.3 91.4% ± 1.0 90.9% ± 1.3 95.9% ± 0.9 gpt-oss-120b 92.4% ± 0.2 93.6% ± 0.3 94.1% ± 1.1 93.4% ± 1.0 97.8% ± 0.3 gpt-oss-20b 92.3% ± 0.9 93.1% ± 1.8 91.7% ± 1.2 92.4% ± 1.0 98.0% ± 0.5 LiveCodeBench granite4-small 15.8% ± 0.3 15.5% ± 0.8 17.4% ± 1.1 15.7% ± 0.6 24.0% ± 0.7 granite4-micro 11.1% ± 0.3 11.5% ± 1.3 10.7% ± 0.6 11.1% ± 0.9 18.2% ± 0.7 llama4-scout 23.9% ± 0.3 24.5% ± 0.6 24.9% ± 0.4 23.9% ± 1.0 30.3% ± 0.6 llama4-maverick 29.0% ± 0.2 28.5% ± 0.3 29.1% ± 0.2 29.3% ± 0.1 36.7% ± 0.2 gpt-oss-120b 30.3% ± 0.8 19.5% ± 1.5 36.1% ± 2.0 35.8% ± 0.8 48.2% ± 0.3 gpt-oss-20b 20.8% ± 0.5 12.5% ± 1.2 8.0% ± 0.9 15.9% ± 0.8 40.2% ± 0.3 Fever granite4-small 76.6% ± 0.6 77.5% ± 0.8 77.9% ± 1.0 78.1% ± 1.3 88.3% ± 0.9 granite4-micro 71.7% ± 0.2 73.6% ± 0.3 73.7% ± 0.8 73.3% ± 1.2 90.3% ± 1.1 llama4-scout 85.6% ± 0.4 85.0% ± 0.2 85.9% ± 1.5 84.1% ± 0.1 93.7% ± 0.8 llama4-maverick 81.6% ± 0.3 81.7% ± 0.6 80.9% ± 0.4 81.0% ± 0.2 85.7% ± 0.3 gpt-oss-120b 86.5% ± 0.2 87.5% ± 0.5 86.7% ± 0.3 87.2% ± 0.0 92.7% ± 0.6 gpt-oss-20b 79.9% ± 0.4 81.3% ± 0.2 79.9% ± 1.0 81.2% ± 0.5 90.6% ± 0.8
4.1. PPDL as an Inference Scaling Framework
This section evaluates PPDL as a unified inference-scaling framework across multiple tasks and models. Our goal is not to claim state-of-the-art task performance, but to demonstrate that PPDL enables users to write a single program and experiment with different inference algorithms without rewriting the flow logic. This allows systematic exploration of which inference strategy works best for a given task and model combination.
Models. We used granite4-small, granite4-micro, gpt-oss-120b, gpt-oss-20b, llama4-maverick, and llama4-scout in our experiments, covering different families and sizes of models. Appendix D includes their release and cutoff dates. We set the model temperature for all experiments to 0.8, and use the default reasoning effort for gpt-oss-120b (medium). All other hyperparameters were left at their default values.
Benchmarks. We use benchmarks that span a variety of tasks and cap all datasets at 500 samples:
• Reasoning: GSM8k (Cobbe et al., 2021) is a dataset of grade-school level math problems; Math500 (Math-500 Dataset) is a curated selection of 500 problems from the Math dataset (Hendrycks et al., 2021), spanning algebra, geometry, number theory, pre-calculus, and probability.
• Code generation: MBPP (Austin et al., 2021) is a collection of mostly basic Python programming tasks; LiveCodeBench (Jain et al., 2025) is a dynamic contamination-free benchmark using fresh problems from LeetCode, AtCoder, and Codeforces. We selected the code generation task and its latest version (v6) with a time window from 8/1/2024 to 5/1/2025.
• Question answering: Fever (Thorne et al., 2018) is a fact checking dataset.
Inference scaling algorithms. We consider the following inference scaling algorithms: majority voting (Maj. Voting), importance sampling (IS), and sequential Monte Carlo (SMC). We run all experiments with 5 particles.
PPDL Programs. For each benchmark, we write a PPDL program to capture the logic of interacting with LLMs and add factors to shift the distribution toward desirable results using both LLM-based judges and rule-based ones. The complete PPDL implementations are in Section E.
• Reasoning: The program asks the LLM to solve the math problem, then extracts the answer and asks the same LLM to judge the correctness of the solution and score it according to the formula shown in Section 2.
• Code generation: The program first asks the LLM to generate an English plan for the problem at hand, then uses an LLM to judge the validity of the plan (scoring accordingly). It then generates a Python function corresponding to the plan by calling the model. It extracts the Python code and uses rule-based judges to check that the solution contains function definitions and to evaluate the number of warnings using flake8. Finally, the same LLM is used to judge the correctness of the solution.
• Question answering: The program first asks the question to the LLM, enabling it to use a Wikipedia search tool. This may result in tool-use requests. We then check whether the topic(s) to be searched are sensible using the same LLM as a judge and call the search tool. We use LLM-as-judge to check whether enough evidence has been gathered and finally call the LLM again to verify or refute the original question given the gathered evidence.
Results. Table 2 reports the results of our experiments. We perform three runs for each task, model, and algorithm and report the mean accuracy and standard deviation. The column labeled IS@1 is the baseline corresponding to a program executed without inference scaling. Similarly, pass@k is an oracle upper bound, where at least one out of k particles has the correct answer. These benchmarks demonstrate how easily a user can experiment with different inference scaling algorithms for a given task and model and choose between them without writing additional code. This is particularly interesting for SMC, which has a more intricate implementation. The results show the accuracy improvements achieved by inference scaling over the baseline and that while simple majority voting is the best-performing algorithm in some cases (e.g., GSM8k with gpt-oss-20b), in other cases importance sampling or SMC performs best.
In general, importance sampling (IS) and SMC are preferable to majority voting when the factor statements provide meaningful information, as they use the factors to shift probability mass toward better traces. Between IS and SMC, SMC is particularly advantageous for longer, deeper flows with informative intermediate factors. IS only reweights completed traces, while SMC can resample during execution at factor points, allowing computation to be redirected toward more promising partial traces earlier in the flow. This gives SMC a more meaningful exploration of the search space in multi-step settings, as demonstrated in the theorem-proving case study below.
4.2. Case Study: Theorem Proving in Rocq
As a case study, we use PPDL to implement a theorem proving agent for Rocq, formerly known as Coq (Rocq Prover Team), a proof assistant, similar to Lean or Isabelle, that can automatically check mathematical proofs. The complete PPDL implementation is provided in Section E.6.
We focus on the MiniF2F dataset (Zheng et al., 2021; Jiang et al., 2022), a popular benchmark for evaluating theorem proving agents (Polu & Sutskever, 2020; Thakur et al., 2024; Mikuła et al., 2023; Wang et al., 2024). The test split comprises 244 high-school level math exercises, ranging from simple algebra to International Mathematics Olympiad problems. While the Lean version of this benchmark is already saturated, with state-of-the-art specialized models with aggressive inference scaling reaching up to 99% accuracy (Varambally et al., 2025), the Rocq version (Viennot et al., 2025) is more recent, and the contamination risk is minimal. The goal of this experiment is not to compare our agent with state-of-the-art solutions, but to measure how much probabilistic inference can improve the performance of a base model on a challenging task.
Experimental setup. We adapt an experiment originally designed for Lean to the Rocq prover to study how different prompting and inference scaling strategies affect LLM-based theorem proving (G. Narozniak, personal communication, 2026). A full proof generation agent alternates between two steps: LLM-based proof synthesis and prover-based verification. The agent implements a simple proof/repair loop: if the verification step fails, the agent lists all errors and prompts the LLM to fix the proof.
For each exercise, we compare three inference scaling strategies under a limit on the total number of tokens that can be used to find the proof: 1) IS@1: repeatedly retry until a proof is found or the token budget is exhausted (this corresponds to sequential scaling); 2) IS@k: run k particles and stop as soon as one of them finds a proof or the token budget is exhausted (this is equivalent to pass@k thanks to the perfect verifier and because scores are ignored when a proof is found); 3) SMC@k: similar to IS, but use the number of errors at each attempt to score the particles and prioritize the most promising proofs. When a proof is found, the agent terminates the execution of all parallel particles and returns the successful proof.
Using PPDL, we evaluate these three strategies on the same program by adjusting the runtime configuration, varying only the inference algorithm and particle count. We run all experiments with gpt-oss-120b, a temperature of 1.0, and a budget of 1M tokens.
Table 3: Number of problems solved out of the 244 MiniF2F-Rocq problems. We present the average ± one standard deviation over three runs.
Particles IS SMC delta 1 72.7 ± 2.9 - - 5 82.7 ± 3.9 84.7 ± 1.2 +2.0 10 84.3 ± 3.9 91.3 ± 1.7 +7.0 20 87.0 ± 1.6 94.3 ± 2.1 +7.3 40 87.7 ± 2.4 95.0 ± 2.4 +7.3
Results. Table 3 presents a summary of the results. We observe that with a constant number of tokens the accuracy varies from 30% (72.7/244 for IS@1) to 39% (95/244 for SMC@40). With a fixed number of particles, SMC always performs better than IS. SMC can resample during execution at factor points, allowing computation to be redirected toward more promising partial traces earlier in the flow. This gives SMC a more meaningful exploration of the search space in multi-step settings. SMC also benefits from having more particles since larger particle populations help preserve diversity during resampling and reduce the risk of collapsing too early onto a narrow set of traces.
Figure 6: Number of MiniF2F-Rocq problems solved as a function of proof/repair steps. Each curve shows the mean over three runs, with shaded regions indicating one standard deviation.
Since the number of tokens is constant, there is a trade-off between the number of proof/repair steps and multiple particles searching solutions in parallel. Figure 6 shows this trade-off for the SMC algorithm (results are similar for IS and shown in Figure 26 in the appendix). A single particle (IS@1) leverages prover feedback across up to 74 sequential repairs whereas SMC@40 goes down to 9 steps. Parallel exploration is more efficient for exploring the proof space and can prove more theorems in a single step, but it exhausts the token budget more quickly.
Our agent is relatively simple, but optimizing this exploration/exploitation trade-off could be even more beneficial for more advanced prompting strategies that leverage feedback from multiple tools (e.g., the prover, specialized search engines, or a natural language reasoner).
5. Related Work
There is not much prior work at the intersection between prompt programming and probabilistic programming. LLaMPPL (Lew et al., 2023) and GenML Control (Loula et al., 2025) apply probabilistic inference engines to the decoding of LLM-generated tokens with SMC and both soft and hard constraints. But unlike our work, they focus on a single LLM call, not a flow of LLM and tool calls. LMQL features hard constraints and beam search over traces (Beurer-Kellner et al., 2023); unlike our work, it lacks soft constraints and probabilistic inference such as SMC. Similarly, EnCompass also supports beam search over traces (Li et al., 2025); however, as it does not track how uncertainty accumulates across factors, it also lacks probabilistic inference. Rollout Roulette uses a process reward model with SMC over token sequences (Puri et al., 2025); in contrast, our work supports a more general set of soft and hard constraints, and supports multi-call flows. Bertsch et al. (2023) reframe inference scaling as probabilistic inference to find the Minimum Bayes Risk sample, but do not explore SMC nor LLM-and-tool flows.
We take inspiration from the rich literature on probabilistic languages (PPLs) that predates prompt programming with LLMs. An overview paper by Gordon et al. (2014) introduces core constructs of probabilistic programming and inference via the Prob PPL. The Stan PPL has been widely adopted in practice (Carpenter et al., 2017). The Church PPL is based on lambda calculus (Goodman et al., 2008). Like PPDL, each of Prob, Stan, and Church tracks and updates a log-probability along a trajectory; but unlike PPDL, none of them interface with LLMs. Some more recent PPLs do interface with neural networks, such as Pyro (Bingham et al., 2019) and DeepStan (Baudart et al., 2021a), but they do not focus on language models, let alone prompt programming.
Another source of inspiration for PPDL is the growing literature on prompt programming languages. We already discussed LMQL and PDL. Guidance focuses on hard constraints to guide generation (Lundberg et al., 2022). Both DSPy (Khattab et al., 2024) and AutoPDL (Spiess et al., 2025) provide support for optimizing prompt programs for an objective function, which could be viewed as a final soft constraint. Other prompting languages include SGLang (Zheng et al., 2024), Vieira (Li et al., 2024), APPL (Dong et al., 2025), and Opp (Mell et al., 2025). Unlike PPDL, none of these are probabilistic languages; while several of the papers include inference scaling examples, those are written by hand, not orthogonal like in PPDL.
Parallel inference scaling scales the number of independent attempts for solving a problem (where each attempt can be a full trace). Examples include Self-consistency (Wang et al., 2023) and Large Language Monkeys (Brown et al., 2024). PPDL makes parallel inference scaling implicit and orthogonal. Sequential inference scaling scales the number of tokens in a single LLM call or the number of LLM calls in a single trajectory. Examples include chain-of-thought (Wei et al., 2022), Self-refine (Madaan et al., 2023), and ReAct agents (Yao et al., 2023b). PDL has been designed to facilitate the implementation of flows that embody these sequential inference scaling approaches, and PPDL directly inherits this property. Besides parallel and sequential, a third style is search-based inference scaling, e.g., Yao et al. (2023a) and Zhou et al. (2024). PPDL makes search-based inference scaling implicit and orthogonal.
Rooted in earlier work on automated machine learning (Feurer et al., 2015; Baudart et al., 2021b), automated prompt optimization uses known question/answer pairs to improve prompts for future questions. More recently, instance optimization applies prompt optimization for a specific new question; examples include TextGrad (Yuksekgonul et al., 2025), Trace (Cheng et al., 2024), and Gepa (Agrawal et al., 2025). Unlike our work, none are PPLs or use probabilistic inference engines. In future work, we plan to integrate some of these techniques.
6. Conclusion
This paper introduces PPDL, a new programming language that unifies prompt programming and probabilistic programming. Prompt programming languages make LLM prompting easy, but struggle with inaccuracy and uncertainty. One solution for boosting accuracy is inference scaling, but unfortunately, manually adding inference scaling to a prompt program sacrifices simplicity and flexibility. Instead, PPDL lets users write the core logic in a simple prompting language, and the interpreter applies orthogonal probabilistic inference engines to search the space of trajectories. As a bonus, since the program returns a distribution, users also get a better feeling for the uncertainty of results.
Limitations. While useful, inference scaling is no silver bullet (Stroebl et al., 2026). Any steering based on factors can only be as good as the information in those factors, which is often imperfect, e.g., based on an LLM-as-a-judge (Zheng et al., 2023). In future work, we plan to mitigate that limitation by calibrating factors, so multiple constraints carry the appropriate relative weight.
Acknowledgements
We would like to thank Theo Stoskopf for all the help and support with the rocq-ml-toolbox (https://github.com/LLM4Rocq/rocq-ml-toolbox) that we used for the theorem-proving case study.
Impact Statement
This paper presents work whose goal is to advance the field of Machine Learning. There are many potential societal consequences of our work, none of which we feel must be specifically highlighted here.
References
Agrawal, L. A., Tan, S., Soylu, D., Ziems, N., Khare, R., Opsahl-Ong, K., Singhvi, A., Shandilya, H., Ryan, M. J., Jiang, M., Potts, C., Sen, K., Dimakis, A. G., Stoica, I., Klein, D., Zaharia, M., and Khattab, O. GEPA: Reflective prompt evolution can outperform reinforcement learning, July 2025. URL https://arxiv.org/abs/2507.19457.
Austin, J., Odena, A., Nye, M., Bosma, M., Michalewski, H., Dohan, D., Jiang, E., Cai, C., Terry, M., Le, Q., and Sutton, C. Program synthesis with large language models, August 2021. URL https://arxiv.org/abs/2108.07732.
Baudart, G., Burroni, J., Hirzel, M., Mandel, L., and Shinnar, A. Compiling Stan to generative probabilistic languages and extension to deep probabilistic programming. In Conference on Programming Language Design and Implementation (PLDI), pp. 497–510, June 2021a. URL https://doi.org/10.1145/3453483.3454058.
Baudart, G., Hirzel, M., Kate, K., Ram, P., Shinnar, A., and Tsay, J. Pipeline combinators for gradual AutoML. In Conference on Neural Information Processing Systems (NeurIPS), pp. 19705–19718, December 2021b. URL https://proceedings.neurips.cc/paper/2021/file/a3b36cb25e2e0b93b5f334ffb4e4064e-Paper.pdf.
Bertsch, A., Xie, A., Neubig, G., and Gormley, M. R. It’s MBR all the way down: Modern generation techniques through the lens of minimum Bayes risk. In Proceedings of the Big Picture Workshop (BigPicture@EMNLP), pp. 108–122, December 2023. URL https://doi.org/10.18653/v1/2023.bigpicture-1.9.
Beurer-Kellner, L., Fischer, M., and Vechev, M. Prompting is programming: A query language for large language models. In Conference on Programming Language Design and Implementation (PLDI), pp. 1946–1969, June 2023. URL https://doi.org/10.1145/3591300.
Bingham, E., Chen, J. P., Jankowiak, M., Obermeyer, F., Pradhan, N., Karaletsos, T., Singh, R., Szerlip, P., Horsfall, P., and Goodman, N. D. Pyro: Deep universal probabilistic programming. Journal of Machine Learning Research (JMLR), 20:1–6, 2019. URL https://www.jmlr.org/papers/v20/18-403.html.
Brown, B., Juravsky, J., Ehrlich, R., Clark, R., Le, Q. V., Re, C., and Mirhoseini, A. Large language monkeys: Scaling inference compute with repeated sampling, July 2024. URL https://arxiv.org/abs/2407.21787.
Carpenter, B., Gelman, A., Hoffman, M., Lee, D., Goodrich, B., Betancourt, M., Brubaker, M. A., Guo, J., Li, P., and Riddell, A. Stan: A probabilistic programming language. Journal of Statistical Software, 76(1):1–37, 2017. URL https://www.jstatsoft.org/article/view/v076i01.
Chen, B., Zhang, F., Nguyen, A., Zan, D., Lin, Z., Lou, J.-G., and Chen, W. CodeT: Code generation with generated tests. In International Conference on Learning Representations (ICLR), May 2023. URL https://openreview.net/forum?id=ktrw68Cmu9c.
Cheng, C.-A., Nie, A., and Swaminathan, A. Trace is the next AutoDiff: Generative optimization with rich feedback, execution traces, and LLMs. In Conference on Neural Information Processing Systems (NeurIPS), December 2024. URL https://proceedings.neurips.cc/paper_files/paper/2024/hash/83ba7056bce2c3c3c27e17397cf3e1f0-Abstract-Conference.html.
Cobbe, K., Kosaraju, V., Bavarian, M., Chen, M., Jun, H., Kaiser, L., Plappert, M., Tworek, J., Hilton, J., Nakano, R., Hesse, C., and Schulman, J. Training verifiers to solve math word problems, October 2021. URL https://arxiv.org/abs/2110.14168.
Del Moral, P., Doucet, A., and Jasra, A. Sequential Monte Carlo samplers. J. Royal Statistical Society: Series B (Statistical Methodology), 68(3):411–436, 2006.
Dong, H., Su, Q., Gao, Y., Li, Z., Ruan, Y., Pekhimenko, G., Maddison, C. J., and Si, X. APPL: A prompt programming language for harmonious integration of programs and large language model prompts. In Annual Meeting of the Association for Computational Linguistics (ACL), July 2025. URL https://aclanthology.org/2025.acl-long.63/.
Feurer, M., Klein, A., Eggensperger, K., Springenberg, J., Blum, M., and Hutter, F. Efficient and robust automated machine learning. In Conference on Neural Information Processing Systems (NIPS), pp. 2962–2970, December 2015. URL http://papers.nips.cc/paper/5872-efficient-and-robust-automated-machine-learning.
Goodman, N., Vikash, M., Roy, D., Bonawitz, K., and Tenenbaum, J. Church: a language for generative models. In Conference on Uncertainty in Artificial Intelligence (UAI), pp. 220–229, 2008. URL https://dslpitt.org/uai/papers/08/p220-goodman.pdf.
Gordon, A. D., Henzinger, T. A., Nori, A. V., and Rajamani, S. K. Probabilistic programming. In ICSE track on Future of Software Engineering (FOSE@ICSE), pp. 167–181, 2014. URL https://doi.org/10.1145/2593882.2593900.
Halstead, Jr., R. H. Multilisp: A language for concurrent symbolic computation. Transactions on Programming Languages and Systems (TOPLAS), 7(4):501–538, October 1985. URL https://doi.org/10.1145/4472.4478.
Hendrycks, D., Burns, C., Kadavath, S., Arora, A., Basart, S., Tang, E., Song, D., and Steinhardt, J. Measuring mathematical problem solving with the math dataset. In NeurIPS Datasets and Benchmarks Track, December 2021. URL https://openreview.net/forum?id=7Bywt2mQsCe.
Jain, N., Han, K., Gu, A., Li, W.-D., Yan, F., Zhang, T., Wang, S., Solar-Lezama, A., Sen, K., and Stoica, I. LiveCodeBench: Holistic and contamination free evaluation of large language models for code. In International Conference on Learning Representations (ICLR), May 2025. URL https://openreview.net/forum?id=chfJJYC3iL.
Jiang, A. Q., Welleck, S., Zhou, J. P., Li, W., Liu, J., Jamnik, M., Lacroix, T., Wu, Y., and Lample, G. Draft, sketch, and prove: Guiding formal theorem provers with informal proofs. In International Conference on Learning Representations (ICLR), 2022. URL https://openreview.net/forum?id=SMa9EAovKMC.
Jimenez, C. E., Yang, J., Wettig, A., Yao, S., Pei, K., Press, O., and Narasimhan, K. SWE-bench: Can language models resolve real-world GitHub issues? In International Conference on Learning Representations (ICLR), May 2024. URL https://openreview.net/forum?id=VTF8yNQM66.
Khattab, O., Singhvi, A., Maheshwari, P., Zhang, Z., Santhanam, K., A, S. V., Haq, S., Sharma, A., Joshi, T. T., Moazam, H., Miller, H., Zaharia, M., and Potts, C. DSPy: Compiling declarative language model calls into self-improving pipelines. In International Conference on Learning Representations (ICLR), May 2024. URL https://openreview.net/forum?id=sY5N0zY5Od.
Lew, A. K., Zhi-Xuan, T., Grand, G., and Mansinghka, V. K. Sequential Monte Carlo steering of large language models using probabilistic programs. In Workshop on Sampling and Optimization in Discrete Space (SODS@ICML), July 2023. URL https://openreview.net/forum?id=Ul2K0qXxXy.
Li, Z., Huang, J., Liu, J., Zhu, F., Zhao, E., Dodds, W., Velingker, N., Alur, R., and Naik, M. Relational programming with foundation models. In Conference on Artificial Intelligence (AAAI), February 2024. URL https://doi.org/10.1609/aaai.v38i9.28934.
Li, Z., Solar-Lezama, A., Yue, Y., and Zheng, S. EnCompass: Enhancing agent programming with search over program execution paths. In Conference on Neural Information Processing Systems (NeurIPS), December 2025. URL https://openreview.net/forum?id=IKVkpjSJzJ.
Loula, J., LeBrun, B., Du, L., Lipkin, B., Pasti, C., Grand, G., Liu, T., Emara, Y., Freedman, M., Eisner, J., Cotterell, R., Mansinghka, V., Lew, A. K., Vieira, T., and O’Donnell, T. J. Syntactic and semantic control of large language models via sequential Monte Carlo. In International Conference on Learning Representations (ICLR), May 2025. URL https://openreview.net/forum?id=xoXn62FzD0.
Lundberg, S., Ribeiro, M. T. C., and et al. Guidance: A guidance language for controlling large language models, November 2022. URL https://github.com/guidance-ai/guidance.
Madaan, A., Tandon, N., Gupta, P., Hallinan, S., Gao, L., Wiegreffe, S., Alon, U., Dziri, N., Prabhumoye, S., Yang, Y., Gupta, S., Majumder, B. P., Hermann, K., Welleck, S., Yazdanbakhsh, A., and Clark, P. Self-refine: Iterative refinement with self-feedback. In Conference on Neural Information Processing Systems (NeurIPS), December 2023. URL https://proceedings.neurips.cc/paper_files/paper/2023/hash/91edff07232fb1b55a505a9e9f6c0ff3-Abstract-Conference.html.
Math-500 Dataset. Math-500 benchmark leaderboard. https://artificialanalysis.ai/evaluations/math-500.
Mell, S., Kallas, K., Zdancewic, S., and Bastani, O. Opportunistically parallel lambda calculus. In Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), pp. 2596–2622, October 2025. URL https://doi.org/10.1145/3763143.
Mikuła, M., Tworkowski, S., Antoniak, S., Piotrowski, B., Jiang, A. Q., Zhou, J. P., Szegedy, C., Kuciński, Ł., Miłoś, P., and Wu, Y. Magnushammer: A transformer-based approach to premise selection. arXiv preprint arXiv:2303.04488, 2023.
Okasaki, C. Purely Functional Data Structures. Cambridge University Press, 1998.
Polu, S. and Sutskever, I. Generative language modeling for automated theorem proving. arXiv preprint arXiv:2009.03393, 2020.
Puri, I., Sudalairaj, S., Xu, G., Xu, K., and Srivastava, A. Rollout roulette: A probabilistic inference approach to inference-time scaling of LLMs using particle-based Monte Carlo methods. In Conference on Neural Information Processing Systems (NeurIPS), December 2025. URL https://openreview.net/forum?id=qPQUrjiA0q.
Rocq Prover Team. The Rocq prover. https://rocq-prover.org/. Accessed: 2026-01-26.
Spiess, C., Vaziri, M., Mandel, L., and Hirzel, M. AutoPDL: Automatic prompt optimization for LLM agents. In Conference on Automated Machine Learning (AutoML), September 2025. URL https://proceedings.mlr.press/v293/spiess25a.html.
Stroebl, B., Kapoor, S., and Narayanan, A. Inference scaling FLaws: The limits of LLM resampling with imperfect verifiers, March 2026. URL https://arxiv.org/abs/2411.17501.
Thakur, A., Tsoukalas, G., Wen, Y., Xin, J., and Chaudhuri, S. An in-context learning agent for formal theorem-proving. In Conference on Language Modeling (COLM), October 2024.
Thorne, J., Vlachos, A., Christodoulopoulos, C., and Mittal, A. FEVER: a large-scale dataset for fact extraction and VERification, March 2018. URL https://arxiv.org/abs/1803.05355.
Varambally, S., Voice, T., Sun, Y., Chen, Z., Yu, R., and Ye, K. Hilbert: Recursively building formal proofs with informal reasoning. arXiv preprint arXiv:2509.22819, 2025.
Vaziri, M., Mandel, L., Spiess, C., and Hirzel, M. PDL: A declarative prompt programming language, October 2024. URL http://arxiv.org/abs/2410.19135.
Viennot, J., Baudart, G., Arias, E. J. G., and Lelarge, M. Minif2f in rocq: Automatic translation between proof assistants - a case study. CoRR, abs/2503.04763, 2025.
Wang, H., Xin, H., Liu, Z., Li, W., Huang, Y., Lu, J., Yang, Z., Tang, J., Yin, J., Li, Z., et al. Proving theorems recursively. arXiv preprint arXiv:2405.14414, 2024.
Wang, X., Wei, J., Schuurmans, D., Le, Q. V., Chi, E. H., Narang, S., Chowdhery, A., and Zhou, D. Self-consistency improves chain of thought reasoning in language models. In International Conference on Learning Representations (ICLR), May 2023. URL https://openreview.net/forum?id=1PL1NIMMrw.
Wei, J., Wang, X., Schuurmans, D., Bosma, M., Ichter, B., Xia, F., Chi, E., Le, Q., and Zhou, D. Chain-of-thought prompting elicits reasoning in large language models. In Conference on Neural Information Processing Systems (NeurIPS), pp. 24824–24837, December 2022. URL https://proceedings.neurips.cc/paper_files/paper/2022/hash/9d5609613524ecf4f15af0f7b31abca4-Abstract-Conference.html.
Yao, S., Yu, D., Zhao, J., Shafran, I., Griffiths, T., Cao, Y., and Narasimhan, K. Tree of thoughts: Deliberate problem solving with large language models. In Conference on Neural Information Processing Systems (NeurIPS), December 2023a. URL https://proceedings.neurips.cc/paper_files/paper/2023/hash/271db9922b8d1f4dd7aaef84ed5ac703-Abstract-Conference.html.
Yao, S., Zhao, J., Yu, D., Du, N., Shafran, I., Narasimhan, K. R., and Cao, Y. ReAct: Synergizing reasoning and acting in language models. In International Conference on Learning Representations (ICLR), May 2023b. URL https://openreview.net/forum?id=WE_vluYUL-X.
Yuksekgonul, M., Bianchi, F., Boen, J., Liu, S., Lu, P., Huang, Z., Guestrin, C., and Zou, J. Optimizing generative AI by backpropagating language model feedback. Nature, 639(8055):609–616, March 2025.
Zheng, K., Han, J. M., and Polu, S. Minif2f: a cross-system benchmark for formal olympiad-level mathematics. arXiv preprint arXiv:2109.00110, 2021.
Zheng, L., Chiang, W.-L., Sheng, Y., Zhuang, S., Wu, Z., Zhuang, Y., Lin, Z., Li, Z., Li, D., Xing, E., Zhang, H., Gonzalez, J. E., and Stoica, I. Judging LLM-as-a-judge with MT-bench and chatbot arena. In Conference on Neural Information Processing Systems (NeurIPS), pp. 46595–46623, 2023. URL https://proceedings.neurips.cc/paper_files/paper/2023/file/91f18a1287b398d378ef22505bf41832-Paper-Datasets_and_Benchmarks.pdf.
Zheng, L., Yin, L., Xie, Z., Sun, C., Huang, J., Yu, C. H., Cao, S., Kozyrakis, C., Stoica, I., Gonzalez, J. E., Barrett, C., and Sheng, Y. SGLang: Efficient execution of structured language model programs. In Conference on Neural Information Processing Systems (NeurIPS), pp. 62557–62583, 2024. URL https://proceedings.neurips.cc/paper_files/paper/2024/file/724be4472168f31ba1c9ac630f15dec8-Paper-Conference.pdf.
Zhou, A., Yan, K., Shlapentokh-Rothman, M., Wang, H., and Wang, Y.-X. Language agent tree search unifies reasoning, acting, and planning in language models. In International Conference on Machine Learning (ICML), pp. 62138–62160, July 2024. URL https://proceedings.mlr.press/v235/zhou24r.html.
A. Example Walk-Through
This section illustrates the execution of the PPDL program from Figure 3 using two different inference algorithms: Importance Sampling (IS) and Sequential Monte Carlo (SMC). Both examples use 5 particles to solve the centered hexagonal number problem, where the task is to generate a Python function that computes the nth centered hexagonal number using the formula 1 + 3n(n − 1).
Importance Sampling execution (Table 4). In IS, all particles execute independently from start to finish. Each particle generates a plan (first row), which is then scored using an LLM-as-a-judge constraint (second row). The particles then generate code solutions (third row), which are scored using a linter-based constraint (fourth row).
The key insight from this execution is how the scoring mechanism differentiates solution quality. Particles 0 and 4 generate correct solutions with the formula 1 + 3*n*(n-1), and receive very low penalty scores (approximately −0.69 after both scoring steps). Particles 1, 2, and 3 generate incorrect formulas and receive much higher penalty scores (ranging from −14.25 to −17.44).
When these scores are normalized into probabilities, particles 0 and 4 each have approximately 50% probability, while the incorrect solutions have negligible probabilities (less than 0.0004% combined). This demonstrates how IS uses scoring to amplify the probability of correct solutions. Without scoring (i.e., using majority voting), the probability of sampling a correct solution would be only 0.4, since only 2 out of 5 particles found the correct formula.
Sequential Monte Carlo execution (Table 5). SMC differs from IS by introducing a resampling step after the first scoring point. Initially, all 5 particles generate plans and receive scores (first two rows). Particles 1 and 2 have significantly better scores (−0.000 000 002 and −0.000 000 009) because their plans contain the correct formula, while the other particles have much worse scores.
The resampling step (indicated by the arrows in Table 5, similar to Figure 1 from the introduction) duplicates the promising particles 1 and 2 while discarding the poorly-scoring particles 0, 3, and 4. After resampling, the particle population consists of three copies derived from particle 1 and two copies derived from particle 2. These resampled particles then continue execution to generate code solutions (third row).
Crucially, all five particles in the second phase now generate correct solutions, because they all descended from particles with good plans. After the final scoring step, all particles have identical scores (−0.69), resulting in a uniform distribution where each solution has equal probability. This execution demonstrates SMC’s ability to focus computational resources on promising execution paths early in the computation, leading to higher-quality final results.
The contrast between these two executions highlights the fundamental difference between IS and SMC: IS evaluates all particles independently and uses scoring only at the end to weigh results, while SMC actively steers the particle population toward promising regions of the solution space through intermediate resampling steps.
Table 4: Example of execution of the program provided in Figure 3 using Importance Sampling. The columns represent the state of the different particles, and the rows represent the values of the variables through the execution. The circles visualize probability magnitudes as in Figure 1. There is a probability of 0.999999453 to sample a correct solution (particles 0 and 4) in this distribution. If we ignore the scores, this trace corresponds to a majority voting execution. In this case, the probability of sampling a correct solution is 0.4.
Variable Particle 0 Particle 1 Particle 2 Particle 3 Particle 4 plan … - The formula ‘3*n*(n+1) + 1‘ is a more direct representation of the nth centered hexagonal num- ber. … … The formula to calculate the nth centered hexag- onal number is given by: 1 + 6 ∗ (1 + 2 + ... + n), which simpli- fies to 1 + 6 ∗ (n ∗ (n + 1)/2). … … The formula for the nth cen- tered hexagonal number is given by: 1 + 6 * (1 + 2 + ... + n), which simplifies to 1 + 6 * (n * (n + 1) / 2). … … The formula for the nth cen- tered hexagonal number is given by: 1 + 6 * (1 + 2 + ... + n), which simplifies to 1 + 6 * (n * (n + 1) / 2). … … - The cor- rect formula for the nth cen- tered hexagonal number is ‘1 + 3*n*(n-1)‘. … score −0.000 000 001 −14.750 000 035 −16.750 000 053 −14.250 001 005 −0.000 000 012 (prob) 0.499 999 729 0.000 000 196 0.000 000 027 0.000 000 324 0.499 999 724 solution def centered_hex... ””” ... ””” return 3*n*(n-1) + 1 def centered_hex... ””” ... ””” if not isinstance(n, int): raise TypeError(”In- put must be an integer.”) if n < 0: raise ValueEr- ror(”Input must be a non-negative integer.”) return 1 + 3 * n * (n + 1) def centered_hex... ””” ... ””” # Calculate the nth centered hexagonal number using the formula return 1 + 6 * (n * (n + 1) // 2) def centered_hex... ””” ... ””” # Calculate the sum of the first n natural numbers sum_of_n = n * (n + 1) // 2 # Calculate the nth centered hexago- nal number result = 1 + 6 * sum_of_n return result def centered_hex... return 1 + 3*n*(n-1) score −0.693 147 182 −15.443 147 216 −17.443 147 234 −14.943 148 186 −0.693 147 192 (prob) 0.499 999 729 0.000 000 196 0.000 000 027 0.000 000 324 0.499 999 724
Table 5: Example of execution of the program provided in Figure 3 using SMC. The arrows represents the resampling step. In this execution, all the particles compute a correct solution and they all have the same probability. After the the first factor, the resampling step duplicates particles 1 and 2 who have a plan that contains the correct formula.
Variable Particle 0 Particle 1 Particle 2 Particle 3 Particle 4 plan … Simplifying this gives 1 + 3n(n + 1) = 3n^2 + 3n + 1. … … By substitut- ing the sum of the first (n-1) natural numbers into the expres- sion, we get ‘1 + 6*((n-1)*n/2)‘, which simplifies to ‘1 + 3*n*(n- 1)‘. … … The formula to calculate the nth centered hexag- onal number is given by: 1 + 6 + 12 + ... + 6(n − 1), which simpli- fies to 3n2 − 3n + 1. … … Substituting the sum of the first ‘n‘ natural numbers into the formula for the nth centered hexagonal num- ber gives ‘1 + 6 * (n * (n + 1) / 2)‘. … … The formula can be sim- plified to 1 + 6(n(n+1)/2). … score −10.75 −0.000 000 002 −0.000 000 009 −15.99 −18.75 (prob) solution def centered_hex... ””” ... ””” if not isinstance(n, int) or n <= 0: raise ValueError(”n must be a positive integer”) return 1 + 3*n*(n-1) def centered_hex... return 1 + 3*n*(n-1) def centered_hex... ””” ... ””” # Calculate the nth centered hexagonal number using the formula: 3n^2 - 3n + 1 return 3*n**2 - 3*n + 1 def centered_hex... return 1 + 3*n*(n-1) def centered_hex... ””” ... ””” return 3*n**2 - 3*n + 1 score −0.69 −0.69 −0.69 −0.69 −0.69 (prob) 0.2 0.2 0.2 0.2 0.2
B. Possible alternatives for Figures 2 and 3
1 l l m = ” w a t s o n x / m e t a - l l a m a / l l a m a - 4 - m a v e r i c k - . . . ” 2 p r o b l e m _ s t a t e m e n t = ( 3 ” W r i t e a f u n c t i o n t o f i n d n t h c e n t e r e d h e x a g o n a l n u m b e r . \ n ” 4 ” a s s e r t c e n t e r e d _ h e x a g o n a l _ n u m b e r ( 1 0 ) = = 2 7 1 \ n ” 5 ) 6 7 m e s s a g e s = [ 8 { 9 ” c o n t e n t ” : ( 10 ” G e n e r a t e a n E n g l i s h p l a n f o r h o w t o g e n e r a t e c o d e ” 11 f ” f o r t h e f o l l o w i n g p r o b l e m : { p r o b l e m _ s t a t e m e n t } ” 12 ) , 13 ” r o l e ” : ” u s e r ” , 14 } 15 ] 16 r e s p o n s e = c o m p l e t i o n ( m o d e l = l l m , m e s s a g e s = m e s s a g e s ) 17 p l a n = r e s p o n s e . c h o i c e s [ 0 ] . m e s s a g e 18 m e s s a g e s = m e s s a g e s + [ p l a n ] 19 m e s s a g e s = m e s s a g e s + [ 20 { 21 ” c o n t e n t ” : ( 22 ” G e n e r a t e a c o m p l e t e e x e c u t a b l e P y t h o n f u n c t i o n ” 23 ” d e f i n i t i o n c o r r e s p o n d i n g t o t h e a b o v e p l a n a n d ” 24 ” p r o b l e m . G e n e r a t e o n l y a s i n g l e f u n c t i o n d e f i n i t i o n . ” 25 ) , 26 ” r o l e ” : ” u s e r ” , 27 } 28 ] 29 r e s p o n s e = c o m p l e t i o n ( m o d e l = l l m , m e s s a g e s = m e s s a g e s ) 30 s o l u t i o n _ s t r = r e s p o n s e . c h o i c e s [ 0 ] . m e s s a g e [ ” c o n t e n t ” ] 31 s o l u t i o n _ m a t c h = r e . f u l l m a t c h ( 32 r ” ( . | \ n ) * ‘ ‘ ‘ p y t h o n \ n ( ? P < c o d e > ( . | \ n ) * ? ) ‘ ‘ ‘ ( . | \ n ) * ” , 33 s o l u t i o n _ s t r , f l a g s = r e . M 34 ) 35 s o l u t i o n = s o l u t i o n _ m a t c h . g r o u p ( ” c o d e ” )
Figure 7: Implementation in Python using LiteLLM of Figure 2.
1 l l m = ” w a t s o n x / m e t a - l l a m a / l l a m a - 4 - m a v e r i c k - . . . ” 2 p r o b l e m _ s t a t e m e n t = ( 3 ” W r i t e a f u n c t i o n t o f i n d n t h c e n t e r e d h e x a g o n a l n u m b e r . \ n ” 4 ” a s s e r t c e n t e r e d _ h e x a g o n a l _ n u m b e r ( 1 0 ) = = 2 7 1 \ n ” 5 ) 6 7 s o l u t i o n s _ a n d _ s c o r e s = [ ] 8 f o r _ i n r a n g e ( n ) : 9 s c o r e = 0 10 m e s s a g e s = [ 11 { 12 ” c o n t e n t ” : ( 13 ” G e n e r a t e a n E n g l i s h p l a n f o r h o w t o g e n e r a t e c o d e ” 14 f ” f o r t h e f o l l o w i n g p r o b l e m : { p r o b l e m _ s t a t e m e n t } ” 15 ) , 16 ” r o l e ” : ” u s e r ” , 17 } 18 ] 19 r e s p o n s e = c o m p l e t i o n ( m o d e l = l l m , m e s s a g e s = m e s s a g e s ) 20 p l a n = r e s p o n s e . c h o i c e s [ 0 ] . m e s s a g e 21 m e s s a g e s = m e s s a g e s + [ p l a n ] 22 c o n s t r a i n t = ( 23 ” T h i s p l a n f o r t h e f o l l o w i n g p r o b l e m i s c o r r e c t . \ n ” 24 f ” { p r o b l e m _ s t a t e m e n t } \ n ” 25 ) 26 s c o r e = s c o r e + u t i l s . l l m _ j u d g e ( l l m , p l a n , c o n s t r a i n t ) 27 m e s s a g e s = m e s s a g e s + [ 28 { 29 ” c o n t e n t ” : ( 30 ” G e n e r a t e a c o m p l e t e e x e c u t a b l e P y t h o n f u n c t i o n ” 31 ” d e f i n i t i o n c o r r e s p o n d i n g t o t h e a b o v e p l a n a n d ” 32 ” p r o b l e m . G e n e r a t e o n l y a s i n g l e f u n c t i o n d e f i n i t i o n . ” 33 ) , 34 ” r o l e ” : ” u s e r ” , 35 } 36 ] 37 r e s p o n s e = c o m p l e t i o n ( m o d e l = l l m , m e s s a g e s = m e s s a g e s ) 38 s o l u t i o n _ s t r = r e s p o n s e . c h o i c e s [ 0 ] . m e s s a g e [ ” c o n t e n t ” ] 39 s o l u t i o n _ m a t c h = r e . f u l l m a t c h ( 40 r ” ( . | \ n ) * ‘ ‘ ‘ p y t h o n \ n ( ? P < c o d e > ( . | \ n ) * ? ) ‘ ‘ ‘ ( . | \ n ) * ” , 41 s o l u t i o n _ s t r , f l a g s = r e . M 42 ) 43 s o l u t i o n = s o l u t i o n _ m a t c h . g r o u p ( ” c o d e ” ) 44 s c o r e = s c o r e + u t i l s . s c o r e _ e r r o r s _ a n d _ w a r n i n g s ( s o l u t i o n ) 45 s o l u t i o n s _ a n d _ s c o r e s . a p p e n d ( ( s o l u t i o n , s c o r e ) ) 46 47 d i s t = C a t e g o r i c a l ( s o l u t i o n s _ a n d _ s c o r e s )
Figure 8: Implementation in Python using LiteLLM of Figure 3 with IS probabilistic inference.
1 l l m = ” w a t s o n x / m e t a - l l a m a / l l a m a - 4 - m a v e r i c k - . . . ” 2 p r o b l e m _ s t a t e m e n t = ( 3 ” W r i t e a f u n c t i o n t o f i n d n t h c e n t e r e d h e x a g o n a l n u m b e r . \ n ” 4 ” a s s e r t c e n t e r e d _ h e x a g o n a l _ n u m b e r ( 1 0 ) = = 2 7 1 \ n ” 5 ) 6 7 s t a t e s = [ ] 8 s c o r e s = [ ] 9 f o r _ i n r a n g e ( n ) : 10 s c o r e = 0 11 m e s s a g e s = [ 12 { 13 ” c o n t e n t ” : ( 14 ” G e n e r a t e a n E n g l i s h p l a n f o r h o w t o g e n e r a t e c o d e ” 15 f ” f o r t h e f o l l o w i n g p r o b l e m : { p r o b l e m _ s t a t e m e n t } ” 16 ) , 17 ” r o l e ” : ” u s e r ” , 18 } 19 ] 20 r e s p o n s e = c o m p l e t i o n ( m o d e l = l l m , m e s s a g e s = m e s s a g e s ) 21 p l a n = r e s p o n s e . c h o i c e s [ 0 ] . m e s s a g e 22 m e s s a g e s = m e s s a g e s + [ p l a n ] 23 c o n s t r a i n t = ( 24 ” T h i s p l a n f o r t h e f o l l o w i n g p r o b l e m i s c o r r e c t . \ n ” 25 f ” { p r o b l e m _ s t a t e m e n t } \ n ” 26 ) 27 s c o r e = s c o r e + u t i l s . l l m _ j u d g e ( l l m , p l a n , c o n s t r a i n t ) 28 s t a t e s . a p p e n d ( m e s s a g e s ) 29 s c o r e s . a p p e n d ( s c o r e ) 30 31 s t a t e s = r e s a m p l e ( s t a t e s , s c o r e s ) 32 33 s o l u t i o n s _ a n d _ s c o r e s = [ ] 34 f o r m e s s a g e s i n s t a t e s : 35 s c o r e = 0 36 m e s s a g e s = m e s s a g e s + [ 37 { 38 ” c o n t e n t ” : ( 39 ” G e n e r a t e a c o m p l e t e e x e c u t a b l e P y t h o n f u n c t i o n ” 40 ” d e f i n i t i o n c o r r e s p o n d i n g t o t h e a b o v e p l a n a n d ” 41 ” p r o b l e m . G e n e r a t e o n l y a s i n g l e f u n c t i o n d e f i n i t i o n . ” 42 ) , 43 ” r o l e ” : ” u s e r ” , 44 } 45 ] 46 r e s p o n s e = c o m p l e t i o n ( m o d e l = l l m , m e s s a g e s = m e s s a g e s ) 47 s o l u t i o n _ s t r = r e s p o n s e . c h o i c e s [ 0 ] . m e s s a g e [ ” c o n t e n t ” ] 48 s o l u t i o n _ m a t c h = r e . f u l l m a t c h ( 49 r ” ( . | \ n ) * ‘ ‘ ‘ p y t h o n \ n ( ? P < c o d e > ( . | \ n ) * ? ) ‘ ‘ ‘ ( . | \ n ) * ” , 50 s o l u t i o n _ s t r , f l a g s = r e . M 51 ) 52 s o l u t i o n = s o l u t i o n _ m a t c h . g r o u p ( ” c o d e ” ) 53 s c o r e = s c o r e + u t i l s . s c o r e _ e r r o r s _ a n d _ w a r n i n g s ( s o l u t i o n ) 54 s o l u t i o n s _ a n d _ s c o r e s . a p p e n d ( ( s o l u t i o n , s c o r e ) ) 55 56 d i s t = C a t e g o r i c a l ( s o l u t i o n s _ a n d _ s c o r e s )
Figure 9: Implementation in Python using LiteLLM of Figure 3 with SMC probabilistic inference.
1 l l m = W a t s o n x L L M ( 2 m o d e l _ i d = ” m e t a - l l a m a / l l a m a - 4 - m a v e r i c k - . . . ” , 3 . . . 4 ) 5 p a r s e r = S t r O u t p u t P a r s e r ( ) 6 7 p r o b l e m _ s t a t e m e n t = ( 8 ” W r i t e a f u n c t i o n t o f i n d n t h c e n t e r e d h e x a g o n a l n u m b e r . \ n ” 9 ” a s s e r t c e n t e r e d _ h e x a g o n a l _ n u m b e r ( 1 0 ) = = 2 7 1 \ n ” 10 ) 11 12 p l a n _ p r o m p t = H u m a n M e s s a g e ( 13 c o n t e n t = ( 14 ” G e n e r a t e a n E n g l i s h p l a n f o r h o w t o g e n e r a t e c o d e ” 15 f ” f o r t h e f o l l o w i n g p r o b l e m : { p r o b l e m _ s t a t e m e n t } ” 16 ) 17 ) 18 19 p l a n _ i n p u t s = [ [ p l a n _ p r o m p t ] ] * n 20 p l a n _ r e s p o n s e s = l l m . b a t c h ( p l a n _ i n p u t s ) 21 22 s t a t e s = [ ] 23 s c o r e s = [ ] 24 f o r r e s p o n s e i n p l a n _ r e s p o n s e s : 25 m e s s a g e s = [ p l a n _ p r o m p t , r e s p o n s e ] 26 p l a n _ t e x t = p a r s e r . i n v o k e ( r e s p o n s e ) 27 c o n s t r a i n t = ( 28 ” T h i s p l a n f o r t h e f o l l o w i n g p r o b l e m i s c o r r e c t . \ n ” 29 f ” { p r o b l e m _ s t a t e m e n t } \ n ” 30 ) 31 s c o r e = u t i l s . l l m _ j u d g e ( l l m , p l a n _ t e x t , c o n s t r a i n t ) 32 s t a t e s . a p p e n d ( m e s s a g e s ) 33 s c o r e s . a p p e n d ( s c o r e ) 34 35 s t a t e s = r e s a m p l e ( s t a t e s , s c o r e s ) 36 37 c o d e _ p r o m p t = H u m a n M e s s a g e ( 38 c o n t e n t = ( 39 ” G e n e r a t e a c o m p l e t e e x e c u t a b l e P y t h o n f u n c t i o n ” 40 ” d e f i n i t i o n c o r r e s p o n d i n g t o t h e a b o v e p l a n a n d ” 41 ” p r o b l e m . G e n e r a t e o n l y a s i n g l e f u n c t i o n d e f i n i t i o n . ” 42 ) 43 ) 44 45 c o d e _ i n p u t s = [ 46 m e s s a g e s + [ c o d e _ p r o m p t ] f o r m e s s a g e s i n s t a t e s 47 ] 48 c o d e _ r e s p o n s e s = l l m . b a t c h ( c o d e _ i n p u t s ) 49 50 s o l u t i o n s _ a n d _ s c o r e s = [ ] 51 f o r r e s p o n s e i n c o d e _ r e s p o n s e s : 52 s o l u t i o n _ s t r = p a r s e r . i n v o k e ( r e s p o n s e ) 53 s o l u t i o n _ m a t c h = r e . f u l l m a t c h ( 54 r ” ( . | \ n ) * ‘ ‘ ‘ p y t h o n \ n ( ? P < c o d e > ( . | \ n ) * ? ) ‘ ‘ ‘ ( . | \ n ) * ” , 55 s o l u t i o n _ s t r , f l a g s = r e . M , 56 ) 57 s o l u t i o n = s o l u t i o n _ m a t c h . g r o u p ( ” c o d e ” ) 58 s c o r e = u t i l s . s c o r e _ e r r o r s _ a n d _ w a r n i n g s ( s o l u t i o n ) 59 s o l u t i o n s _ a n d _ s c o r e s . a p p e n d ( ( s o l u t i o n , s c o r e ) ) 60 61 d i s t = C a t e g o r i c a l ( s o l u t i o n s _ a n d _ s c o r e s )
Figure 10: Implementation in Python using LangChain of Figure 3 with SMC probabilistic inference.
This section demonstrates how the PPDL programs from Figures 2 and 3 can be implemented using standard Python libraries. These implementations illustrate both the expressiveness advantages of PPDL and its orthogonality between program and inference scaling startegy. We present four implementations: a baseline using LiteLLM, importance sampling (IS) and sequential Monte Carlo (SMC) variants with LiteLLM, and an SMC implementation using LangChain that exploits parallelism.
First, Figure 7 corresponds to the implementation of Figure 2 using LiteLLM (https://github.com/BerriAI/litellm) to handle LLM calls. This code has the same structure as the PDL code but requires explicit message building and accumulation (Lines 7-15, and 18-28). It also requires accessing the LLM response data structure (Lines 17 and 30).
Figure 8 presents an implementation of Figure 3 using the IS inference algorithm. The implementation wraps the baseline code in a loop (Line 8) that creates n independent particles. Each particle maintains a log-probability score (Lines 26 and 44) that is used to construct a weighted categorical distribution over solutions (Line 47). This implementation is purely sequential, in particular, each model call is done one after the other.
To implement Figure 3 with SMC, the IS code is restructured as shown in Figure 9. The key difference is that particle execution is split into two phases separated by a resampling step (Line 31): the first loop (Lines 9-29) generates and scores plans, the second loop (Lines 34-54) generates code. This allows SMC to focus computational resources on promising particles after the first scoring point. The resample function samples n states from the distribution of particle states.
1 d e f r e s a m p l e ( s t a t e s , s c o r e s ) :
2 n = l e n ( s t a t e s )
3 d = C a t e g o r i c a l ( z i p ( s t a t e s , s c o r e s ) )
4 r e t u r n [ d . s a m p l e ( ) f o r _ i n r a n g e ( n ) ]
The SMC algorithm can be implemented using prompt programming frameworks like LangChain, as shown in Figure 10. This implementation exploits LangChain’s batch API (Lines 21 and 49) to execute particles in parallel, significantly reducing wall-clock time. The batch API sends multiple prompts to the LLM simultaneously.
Compared to these implementations, PPDL provides a high-level abstraction that separates the probabilistic specification from inference implementation details, allowing the runtime to automatically optimize execution (e.g., through parallelism) without programmer intervention.
C. Semantics
In this section, we present semantics of PPDL.
The syntax of PPDL using the flow-style of YAML is the following:
pdl ::= { defs:{x:pdl, . . . ,x:pdl}, body, parser:parser, contribute:contribute, def:x }
body ::= data:expr | code:pdl,lang:string | model:expr,input:pdl | if:expr,then:pdl,else:pdl | sequence:[pdl, . . . ,pdl],join:join | while:expr,repeat:pdl,join:join | function:types,return:pdl | call:expr,args:expr | factor:expr expr ::= null | bool | number | string | ${jinja_expr} | [expr, . . . ,expr] | {x:expr, . . . ,x:expr}
A program is a block comprising a set of variable definitions, the block body (i.e., the instruction to evaluate), a parser to extract the result from the return value of the body, a flag indicating whether the result contributes to the context, and the name of a variable to store this result.
The body of a block can be an expression (data), some code in Python, Shell, Jinja, or PDL, an LLM call with its input, a conditional, a sequence of blocks with a join operator to gather result values, a loop with a join operator to gather the results of each iteration, a function definition, a function call, or a factor statement to update the score. The join operator is a function that takes a list as input and returns a value. In the concrete syntax of PPDL, {join:{as:text}} corresponds to the string concatenation, {join:{as:lastOf}} returns the last element of the list, and {join:{as:array}} is the identity function.
Types (type) are a subset of JSON Schema, the parsers (parser) are regular expressions, and the contribute flag is defined as follows:
contribute ::= [] | [pdl_context]
The ideal semantics of a PPDL program p is defined by the infinite number of executions of the weighted sampler associated to the program p and the normalization of the weights to obtain a categorical distribution:
{p/S ⇒∗ vi/Si}1≤i≤N wi = exp(S′i[pdl_score])1≤i≤N W = 1≤i≤N wi p/S λU. 1≤i≤N(wi/W) × δvi(U)
The reduction ⇒∗ is the transitive closure of the weighted sampler semantics and N → ∞.
The semantics of weighted sampler p is defined Figure 11 by the reduction p/S ⇒ p_or_v/S′ such that, given an environment S, the program p evaluates to the updated environment S′, and rewrites into a new program or a value.
The semantics of variable definitions is defined Figure 12 by the reduction defs/S defs − → defs′/S′ such that, given an environment S, the definitions defs evaluates to the updated environment S′, and rewrites into a new set of definitions defs′.
The semantics of a block body b is defined Figure 13 by the reduction b/S → b_or_v/S′ such that, given an environment S, the block body b evaluates to the updated environment S′, and rewrites into a new block body or a value.
The semantics of an expression e is defined Figure 14 by the reduction S ⊢ e ⇓ v such that, given an environment S, the expression e evaluates a value. The reduction S ⊢ c ⇓l v uses the semantics of the language l to evaluate the code c to a value v. Evaluation of expressions and external code are not supposed to do side effects.
The semantics of parsing a value v by the parser parser to extract a value v′ is defined by the semantics of Python regular expressions and is noted parser, v parse − → v′.
The semantics of contribute is defined Figure 15 by the reduction S, v, contribute contrib − → S′ such that, given an environment S, the value v, and the contribute flag contribute produces a new environment S′.
defs/S defs − → {}/S1 block_body/S1 → v/S2 parser, v parse − → v′ S2, v′, contribute contrib − → S3 S′ = S3[x ← v′] {defs:defs,block_body,parser:parser,contribute:contribute,def:x}/S ⇒ v′/S′ defs/S defs − → defs′/S′ defs′ = {} {defs:defs,block_body,parser:parser,contribute:contribute,def:x}/S ⇒ {defs:defs′,block_body,parser:parser,contribute:contribute,def:x}/S′ defs/S defs − → {}/S1 block_body/S1 → b/S′ {defs:defs,block_body,parser:parser,contribute:contribute,def:x}/S ⇒ {defs:{},b,parser:parser,contribute:contribute,def:x}/S′
Figure 11: Semantics of a block
{}/S defs − → {}/S pdl1/S ⇒ pdl′1/S1 {x1:pdl1,x2:pdl2, . . . ,xn:pdln}/S defs − → {x1:pdl′1,x2:pdl2, . . . ,xn:pdln}/S1 pdl1/S ⇒ v1/S1 {x2:pdl2, . . . ,xn:pdln}/S1[x1 ← v1] defs − → defs/S′ {x1:pdl1,x2:pdl2, . . . ,xn:pdln}/S defs − → defs/S′
Figure 12: Semantics of defs field.
S ⊢ e ⇓ v data:e/S → v/S S ⊢ p ⇓ c S ⊢ c ⇓l v code:p,lang:l/S → v/S S ⊢ model ⇓ m S ⊢ input ⇓ i sample(m, i) = v model:model,input:input/S → v/S v = j(vs) sequence:[],join:jvs/S → v/S p1/S ⇒ v1/S1 sequence:[p2 . . . ,pn],join:jvs+[v1]/S1 → p′/S′ sequence:[p1,p2 . . . ,pn],join:jvs/S → p′/S′ p1/S ⇒ p′1/S1 sequence:[p1,p2 . . . ,pn],join:jvs/S → sequence:[p′1 . . . ,pn],join:jvs/S1 S ⊢ c ⇓ true p1/S ⇒ p′1/S′ if:c,then:p1,else:p2/S → p′1/S′ S ⊢ c ⇓ false p2/S ⇒ p′2/S′ if:c,then:p1,else:p2/S → p′2/S′ S ⊢ e ⇓ false while:e,repeat:p,join:jvs/S → j(vs)/S S ⊢ e ⇓ true p/S ⇒ v/S′ while:e,repeat:p,join:jvs/S → while:e,repeat:p,join:jvs+[v]/S′ S ⊢ e ⇓ w S′ = S[pdl_score ← S[pdl_score] + w] factor:e/S → data:””/S′ function:t,return:p/S → function:t,return:p, scope:S/S S ⊢ f ⇓ function:t,return:p, scope:Sf S ⊢ args ⇓ args′ args′ ∈ tp/Sf[pdl_context ← S[pdl_context], pdl_score ← S[pdl_score]] + args′ ⇒ v/S′fS′ = S[pdl_context ← S′f[pdl_context], pdl_score ← S′f[pdl_score]] call:f,args:args/S → v/S′ S ⊢ f ⇓ function:t,return:p, scope:Sf S ⊢ args ⇓ args′ args′ ∈ tp/Sf[pdl_context ← S[pdl_context], pdl_score ← S[pdl_score]] + args′ ⇒ p′/S′fS′ = S[pdl_context ← S′f[pdl_context], pdl_score ← S′f[pdl_score]] call:f,args:args/S → call:function:t,return:p′, scope:S′f,args:args′/S′
Figure 13: Semantics of block bodies.
c ∈ (null ∪ bool ∪ numberstring) S ⊢ c ⇓ c S ⊢ e ⇓jinja v S ⊢ ${e} ⇓ v {S ⊢ ei ⇓ vi}1≤i≤N S ⊢ [e1, . . . ,en] ⇓ [v1, . . . ,vn] {S ⊢ ei ⇓ vi}1≤i≤N S ⊢ {x1:e1, . . . ,xn:en} ⇓ {x1:v1, . . . ,xn:vn}
Figure 14: Semantics of expressions.
S, v, [] contrib − → S ctx = S[pdl_context] + [{content:v}] S′ = S[pdl_context ← ctx] S, v, [pdl_context] contrib − → S′
Figure 15: Semantics of contribute field.
D. Models used in experiments
Table 6 shows the selection of LLMs used in experiments.
Table 6: Large language models used in experiments.
Model Size Dates total active cutoff release granite4-small 32b 9b 11/2024 10/2025 granite4-micro 3b 3b 4/2024 10/2025 gpt-oss-120b 117b 5b 6/2024 8/2025 gpt-oss-20b 21b 4b 6/2024 8/2025 llama4-maverick 400b 17b 8/2024 4/2025 llama4-scout 109b 17b 8/2024 4/2025
E. Benchmark Code
This section presents the complete PPDL programs used in the evaluation (Section 4). Each program demonstrates how PPDL enables declarative specification of LLM workflows with probabilistic inference through factor statements. The programs use LLM-as-a-judge and rule-based constraints to guide inference toward correct solutions.
E.1. GSM8k
The GSM8k program (Figure 16) solves grade-school math problems through a simple three-step workflow. First, it prompts the LLM to solve the problem and generate the final answer prefixed by #### (Lines 2-8). Second, it extracts the numerical answer using Python code (Lines 9-16). Third, it applies an LLM-as-a-judge factor (Line 18-28) to score the solution’s correctness (Lines 18-28). The fallback attribute (Lines 30-31) assigns a large negative score if an error occurs, effectively filtering out malformed responses during inference.
1 l a s t O f :
2 - >
3 Q u e s t i o n : $ { p r o b l e m }
4 R e a s o n a b o u t t h i s m a t h p r o b l e m a n d s o l v e i t . G e n e r a t e
5 t h e f i n a l a n s w e r o n t h e l a s t l i n e p r e f i x e d b y ‘ # # # # ‘
6 - m o d e l : $ { m o d e l }
7 d e f : s o l u t i o n
8 p a r a m e t e r s : $ { p a r a m e t e r s }
9 - l a n g : p y t h o n
10 d e f : r e s u l t
11 c o d e : |
12 f r o m p d l . o p t i m i z e . p a r s e _ n u m b e r i m p o r t (
13 e x t r a c t _ m a t h _ a n s w e r
14 )
15 r e s u l t _ l i n e = s o l u t i o n . s p l i t l i n e s ( ) [ - 1 ]
16 r e s u l t = e x t r a c t _ m a t h _ a n s w e r ( r e s u l t _ l i n e )
17
18 - d e f s :
19 c o n s t r a i n t : >
20 I s t h e s o l u t i o n b e l o w t o t h e f o l l o w i n g m a t h p r o b l e m
21 c o r r e c t ?
22
23
24 M a t h P r o b l e m : $ { p r o b l e m }
25
26 S o l u t i o n : $ { r e s u l t }
27 f a c t o r :
28 $ { s t d l i b . l l m _ a s _ j u d g e ( m o d e l , c o n s t r a i n t , p a r a m e t e r s ) }
29 - $ { r e s u l t }
30 f a l l b a c k :
31 f a c t o r : - 1 0 0
Figure 16: PPDL program for GSM8k benchmark.
E.2. Math500
The Math500 program (Figure 17) follows a similar structure to GSM8k but uses a more sophisticated judging strategy. After generating the solution (Lines 2-5), it uses an LLM-as-a-judge to perform line-by-line reasoning analysis (Lines 6-19), asking the judge to identify any errors in the solution’s reasoning. This more detailed validation is appropriate for the harder problems in Math500, which span algebra, geometry, number theory, pre-calculus, and probability. Like GSM8k, it uses a fallback to handle failures.
1 l a s t O f :
2 - ” P r o b l e m : $ { p r o b l e m } ”
3 - m o d e l : $ { m o d e l }
4 d e f : s o l u t i o n
5 p a r a m e t e r s : $ { p a r a m e t e r s }
6 - d e f s :
7 c o n s t r a i n t : >
8 C o n s i d e r t h e s o l u t i o n b e l o w t o t h e f o l l o w i n g m a t h
9 p r o b l e m . R e a d i t l i n e b y l i n e a n d r e a s o n a b o u t i t
10 t o i d e n t i f y a n y e r r o r s i n r e a s o n i n g .
11 I f n o i s s u e s a r e f o u n d , r e s p o n d T r u e . I f a n y i s s u e
12 i s f o u n d , r e s p o n d F a l s e .
13
14
15 M a t h P r o b l e m : $ { p r o b l e m }
16
17 S o l u t i o n : $ { s o l u t i o n }
18 f a c t o r :
19 $ { s t d l i b . l l m _ a s _ j u d g e ( m o d e l , c o n s t r a i n t , p a r a m e t e r s ) }
20 - $ { s o l u t i o n }
21 f a l l b a c k :
22 f a c t o r : - 1 0 0
Figure 17: PPDL program for Math500 benchmark.
E.3. MBPP
The MBPP program (Figure 18) implements a multi-stage code generation workflow with three scoring points. First, it generates an English plan (Lines 5-12) and scores it using an LLM-as-a-judge (Lines 13-26). Second, it generates Python code based on the plan (Lines 27-49), with regex parsing to extract code from markdown blocks (Lines 41-43). Third, it applies multiple constraints: a rule-based check for function definitions (Line 50), a linter-based score using flake8 warnings (Line 51), and a final LLM-as-a-judge for correctness (Lines 52-66). This demonstrates PPDL’s ability to combine different types of constraints—LLM-based, rule-based, and tool-based—in a single program. The program imports utility functions from utils.pdl (Lines 1-3).
1 d e f s :
2 u t i l s :
3 i m p o r t : u t i l s . p d l
4 l a s t O f :
5 - >
6 G e n e r a t e a n E n g l i s h p l a n f o r h o w t o g e n e r a t e c o d e f o r
7 t h e f o l l o w i n g p r o b l e m :
8
9 $ { p r o b l e m }
10 - m o d e l : $ { m o d e l }
11 p a r a m e t e r s : $ { p a r a m e t e r s }
12 d e f : p l a n
13 - d e f s :
14 c o n s t r a i n t : >
15 C o n s i d e r t h e f o l l o w i n g p l a n f o r g e n e r a t i n g c o d e f o r
16 t h e c o d i n g p r o b l e m b e l o w :
17
18 C o d i n g P r o b l e m : $ { p r o b l e m }
19
20
21 P l a n : $ { p l a n }
22
23
24 I s t h e p l a n c o r r e c t ?
25 f a c t o r :
26 $ { s t d l i b . l l m _ a s _ j u d g e ( m o d e l , c o n s t r a i n t , p a r a m e t e r s ) }
27 - >
28 G e n e r a t e a c o m p l e t e e x e c u t a b l e P y t h o n f u n c t i o n
29 d e f i n i t i o n c o r r e s p o n d i n g t o t h e a b o v e p l a n f o r t h e p r o m p t .
30 G e n e r a t e a s i n g l e f u n c t i o n d e f i n i t i o n o n l y a n d n o t h i n g
31 e l s e . D o n o t i n c l u d e d o c s t r i n g s .
32
33
34 $ { p r o b l e m }
35 - m o d e l : $ { m o d e l }
36 d e f : r e s p o n s e
37 p a r a m e t e r s : $ { p a r a m e t e r s }
38 - d e f s :
39 s o l u t i o n :
40 d a t a : $ { r e s p o n s e }
41 p a r s e r :
42 r e g e x : ( . | \ n ) * ‘ ‘ ‘ p y t h o n \ n ( ? P < c o d e > ( . | \ n ) * ? ) ‘ ‘ ‘ ( . | \ n ) *
43 s p e c : { c o d e : s t r i n g }
44 - i f : $ { s o l u t i o n = = N o n e }
45 t h e n :
46 d e f s :
47 s o l u t i o n :
48 d a t a :
49 c o d e : $ { r e s p o n s e }
50 - f a c t o r : $ { u t i l s . c o n t a i n s _ f u n c t i o n s ( s o l u t i o n . c o d e ) }
51 - f a c t o r : $ { u t i l s . e v a l _ n u m b e r _ o f _ w a r n i n g s ( s o l u t i o n ) }
52 - d e f s :
53 c o n s t r a i n t : >
54 C o n s i d e r t h e f o l l o w i n g g e n e r a t e d c o d e f o r t h e c o d i n g
55 p r o b l e m b e l o w :
56
57 C o d i n g P r o b l e m : $ { p r o b l e m }
58
59
60 C o d e : $ { s o l u t i o n }
61
62
63 I s t h e s o l u t i o n c o r r e c t ?
64
65 f a c t o r :
66 $ { s t d l i b . l l m _ a s _ j u d g e ( m o d e l , c o n s t r a i n t , p a r a m e t e r s ) }
67 - $ { s o l u t i o n . c o d e | d e f a u l t ( ” ” ) }
Figure 18: PPDL program for MBPP benchmark.
E.4. LiveCodeBench
The LiveCodeBench program (Figure 19) adapts the MBPP workflow for more challenging programming problems. It follows the same plan-then-code structure (Lines 5-12 for planning, Lines 27-42 for code generation) but requires the generated function to be named main and use input() for reading inputs (Lines 30-32), matching the LiveCodeBench format. The program applies three factor statements: for the plan (Lines 13-26), for linter warnings (Lines 43-44), and for solution correctness (Lines 45-58).
1 d e f s :
2 u t i l s :
3 i m p o r t : . . / m b p p / u t i l s . p d l
4 l a s t O f :
5 - >
6 G e n e r a t e a n E n g l i s h p l a n f o r h o w t o g e n e r a t e c o d e f o r
7 t h e f o l l o w i n g p r o b l e m :
8
9 $ { p r o b l e m }
10 - m o d e l : $ { m o d e l }
11 p a r a m e t e r s : $ { p a r a m e t e r s }
12 d e f : p l a n
13 - d e f s :
14 j u d g e _ p r o m p t : >
15 C o n s i d e r t h e f o l l o w i n g p l a n f o r g e n e r a t i n g c o d e f o r
16 t h e c o d i n g p r o b l e m b e l o w :
17
18 C o d i n g P r o b l e m : $ { p r o b l e m }
19
20
21 P l a n : $ { p l a n }
22
23
24 I s t h e p l a n c o r r e c t ?
25 f a c t o r :
26 $ { s t d l i b . l l m _ a s _ j u d g e ( m o d e l , j u d g e _ p r o m p t , p a r a m e t e r s ) }
27 - >
28 G e n e r a t e a c o m p l e t e e x e c u t a b l e P y t h o n f u n c t i o n
29 d e f i n i t i o n c o r r e s p o n d i n g t o t h e a b o v e p l a n f o r t h e p r o m p t .
30 G e n e r a t e a s i n g l e f u n c t i o n d e f i n i t i o n c a l l e d ‘ m a i n ‘ o n l y
31 a n d n o t h i n g e l s e . I n p u t s t o t h e f u n c t i o n s h o u l d b e g i v e n
32 u s i n g ‘ i n p u t ( ) ‘ .
33
34 G e n e r a t e a s i n g l e f u n c t i o n c a l l t o t h e m a i n f u n c t i o n .
35
36 $ { p r o b l e m }
37 - m o d e l : $ { m o d e l }
38 p a r a m e t e r s : $ { p a r a m e t e r s }
39 d e f : s o l u t i o n
40 p a r s e r :
41 r e g e x : ( . | \ n ) * ‘ ‘ ‘ p y t h o n \ n ( ? P < c o d e > ( . | \ n ) * ? ) ‘ ‘ ‘ ( . | \ n ) *
42 s p e c : { c o d e : s t r i n g }
43 - f a c t o r :
44 $ { u t i l s . e v a l _ n u m b e r _ o f _ w a r n i n g s ( r e s p o n s e = s o l u t i o n ) }
45 - d e f s :
46 j u d g e _ p r o m p t : >
47 C o n s i d e r t h e f o l l o w i n g g e n e r a t e d c o d e f o r t h e
48 c o d i n g p r o b l e m b e l o w :
49
50 C o d i n g P r o b l e m : $ { p r o b l e m }
51
52
53 C o d e : $ { s o l u t i o n }
54
55
56 I s t h e s o l u t i o n c o r r e c t ?
57 f a c t o r :
58 $ { s t d l i b . l l m _ a s _ j u d g e ( m o d e l , j u d g e _ p r o m p t , p a r a m e t e r s ) }
59 - $ { s o l u t i o n . c o d e | d e f a u l t ( ” ” ) }
60 f a l l b a c k :
61 f a c t o r : - 1 0 0
Figure 19: PPDL program for LiveCodeBench benchmark.
E.5. Fever
The Fever fact-checking program demonstrates PPDL’s tool-use capabilities through a three-part workflow. Figure 20 defines a Wikipedia search tool using PPDL’s function declaration (Lines 2-27), which wraps a Python implementation that handles disambiguation and errors. The tool signature is exposed to the LLM (Lines 28-30).
Figure 21 implements the evidence gathering loop. After the LLM generates a response with tool calls (Lines 2-7), the program iterates over each tool call using a for loop (Lines 8-58). For each search request, it validates the topic using an LLM-as-a-judge (Lines 28-45) before calling the search tool (Lines 46-48). This prevents wasting API calls on irrelevant searches. The evidence from all searches is joined with newlines (Lines 53-54).
Figure 22 performs the final verification. It first checks whether enough evidence has been gathered using an LLM-as-a-judge (Lines 1-18), then prompts the LLM to determine if the claim is true or false based on the evidence (Lines 19-30). This three-part structure demonstrates how PPDL programs can be modularized across multiple files while maintaining a coherent probabilistic workflow.
1 d e f s :
2 s e a r c h :
3 d e s c r i p t i o n : W i k i p e d i a s e a r c h
4 f u n c t i o n :
5 t o p i c :
6 t y p e : s t r i n g
7 d e s c r i p t i o n : T o p i c t o b e s e a r c h e d
8 r e t u r n :
9 d e f : r e s u l t
10 l a n g : p y t h o n
11 c o d e : |
12 i m p o r t w a r n i n g s , w i k i p e d i a
13 w a r n i n g s . s i m p l e f i l t e r ( ” i g n o r e ” )
14
15 d e f m a i n ( t o p i c : s t r , * a r g s , * * k w a r g s ) - > s t r :
16 t r y :
17 r e t u r n w i k i p e d i a . s u m m a r y ( t o p i c )
18 e x c e p t w i k i p e d i a . D i s a m b i g u a t i o n E r r o r a s d :
19 r e t u r n (
20 f ” \ ” { t o p i c } \ ” m a y r e f e r t o o n e o f { d . a r g s [ 1 ] } . ”
21 ” P l e a s e r e t r y t h e s e a r c h w i t h a m o r e ”
22 ” s p e c i f i c s u b j e c t . ”
23 )
24 e x c e p t w i k i p e d i a . W i k i p e d i a E x c e p t i o n a s e :
25 r e t u r n s t r ( e )
26
27 r e s u l t = m a i n ( t o p i c )
28 t o o l s :
29 d a t a :
30 - $ { s e a r c h . s i g n a t u r e }
Figure 20: PPDL program for Fever benchmark (Part 1: tool definition).
1 l a s t O f :
2 - $ { p r o b l e m }
3 - m o d e l : $ { m o d e l }
4 d e f : r e s p o n s e
5 m o d e l R e s p o n s e : a c t i o n
6 p a r a m e t e r s : $ { d i c t ( p a r a m e t e r s , t o o l s = t o o l s ) }
7 p a r s e r : j s o n
8 - d e f : e v i d e n c e
9 f o r :
10 t o o l _ c a l l : $ { a c t i o n . c h o i c e s [ 0 ] . m e s s a g e . t o o l _ c a l l s }
11 r e p e a t :
12 t e x t :
13 - i f : $ { t o o l _ c a l l . f u n c t i o n . n a m e = = ” s e a r c h ” }
14 t h e n :
15 d e f s :
16 a r g s :
17 d a t a : $ { t o o l _ c a l l . f u n c t i o n . a r g u m e n t s }
18 p a r s e r : j s o n
19 t o p i c :
20 t e x t : $ { a r g s [ ” t o p i c ” ] }
21 f a l l b a c k :
22 d e f s :
23 a r g s :
24 d a t a : $ { a r g s }
25 p a r s e r : j s o n
26 t e x t : $ { a r g s [ ” t o p i c ” ] }
27 l a s t O f :
28 - d e f s :
29 j u d g e _ p r o m p t : >
30 I s t h e t o p i c b e l o w a g o o d t o p i c t o s e a r c h
31 i n o r d e r t o a n s w e r t h e f o l l o w i n g q u e s t i o n :
32
33 Q u e s t i o n : $ { p r o b l e m }
34
35
36 T o p i c :
37
38 $ { t o p i c }
39
40
41 R e s p o n d w i t h o n l y ( ’ t r u e ’ / ’ f a l s e ’ ) .
42 f a c t o r : >
43 $ { s t d l i b . l l m _ a s _ j u d g e ( m o d e l ,
44 j u d g e _ p r o m p t ,
45 p a r a m e t e r s ) }
46 - c a l l : $ { s e a r c h }
47 a r g s :
48 t o p i c : $ { t o p i c }
49 e l s e :
50 f a c t o r : - 1 0 0
51 f a l l b a c k :
52 f a c t o r : - 1 0 0
53 j o i n :
54 w i t h : ” \ n ”
55 f a l l b a c k :
56 f a c t o r : - 1 0 0
Figure 21: PPDL program for Fever benchmark (Part 2: evidence gathering).
1 - d e f s :
2 j u d g e _ p r o m p t : >
3 I s t h e e v i d e n c e b e l o w e n o u g h t o s u p p o r t o r r e f u t e >
4 t h e f o l l o w i n g p r o b l e m :
5
6 $ { p r o b l e m }
7
8
9 E v i d e n c e :
10
11 $ { r e s p o n s e }
12
13 $ { e v i d e n c e }
14
15
16 R e s p o n d w i t h o n l y ( ’ t r u e ’ / ’ f a l s e ’ ) .
17 f a c t o r :
18 $ { s t d l i b . l l m _ a s _ j u d g e ( m o d e l , j u d g e _ p r o m p t , p a r a m e t e r s ) }
19 - m o d e l : $ { m o d e l }
20 p a r a m e t e r s : $ { p a r a m e t e r s }
21 i n p u t : |
22 C o n s i d e r t h e e v i d e n c e :
23 $ { r e s p o n s e }
24 $ { e v i d e n c e }
25
26 I s t h e f o l l o w i n g s t a t e m e n t t r u e o r f a l s e ?
27 $ { p r o b l e m }
28
29 R e s p o n d w i t h o n l y ( ’ t r u e ’ / ’ f a l s e ’ ) .
Figure 22: PPDL program for Fever benchmark (Part 3: final verification).
E.6. MiniF2F
The MiniF2F theorem proving agent demonstrates PPDL’s capabilities for complex iterative workflows with external tool verification. This program implements the proof/repair loop described in the case study (Section 4): an LLM generates Rocq/Coq proofs that are verified by the Rocq proof assistant, with errors fed back to guide repair attempts.
Figure 23 shows the initialization phase. The program sets up logging infrastructure (Lines 2-7) and initializes a proof checker that interfaces with the Rocq prover using the rocq-ml-toolbox (https://github.com/LLM4Rocq/rocq-ml-toolbox) (Lines 8-13). It then prompts the LLM with both the formal Rocq statement and an informal description of the theorem to prove (Lines 24-51), providing an example proof format to guide the LLM’s output.
Figure 24 implements the core proof/repair loop using a repeat block (Lines 1-55). In each iteration, the LLM generates a proof attempt (Lines 8-11), which is parsed to extract the Rocq code (Lines 12-24). The proof is then verified by calling the Rocq checker (Lines 26-28). If verification fails (Lines 30-47), a factor of −1 is applied (Line 39) to score this attempt, and the error message is fed back to the LLM to guide the next repair attempt (Lines 40-46). This scoring mechanism allows SMC to prioritize particles with fewer errors. The loop continues until either a proof is found or the token budget is exhausted (Line 53), with a maximum iteration limit (Line 54).
Figure 25 performs final verification and result collection. After the loop terminates, it double-checks the proof correctness (Lines 7-10) and logs the final status (Lines 11-24). If the proof is complete, it records the proof, the number of steps, and the token usage (Lines 25-36); then raises an exception to signal success and terminate all parallel particles (Line 35). This early termination mechanism is crucial for efficiency: once any particle finds a valid proof, the entire computation stops, avoiding wasted token usage.
This three-part structure demonstrates PPDL’s ability to express complex agent workflows with iterative refinement, external tool integration, probabilistic scoring based on intermediate feedback, and coordinated termination across parallel executions.
1 d e f s :
2 l o g g e r :
3 a g g r e g a t o r :
4 f i l e :
5 $ { l o g d i r } / l o g s _ $ { n a m e } _ $ { p d l _ p a r t i c l e _ i d } . t x t
6 f l u s h : t r u e
7 m o d e : w
8 c h e c k e r :
9 l a n g : p y t h o n
10 c o d e : |
11 f r o m p r o o f _ c h e c k e r i m p o r t C h e c k e r
12 w o r k s p a c e = a g e n t _ p a r a m s . g e t ( ” w o r k s p a c e ” , ” ” )
13 r e s u l t = C h e c k e r ( w o r k s p a c e = w o r k s p a c e )
14 t o k e n s : 0
15 l a s t O f :
16 - t e x t : |
17
18
19 S T A R T I N G P R O O F .
20
21 G o a l : $ { f o r m a l _ s t a t e m e n t }
22 c o n t r i b u t e : [ l o g g e r , s t d o u t ]
23 - t e x t : |
24 P l e a s e p r o v i d e a p r o o f f o r t h e f o l l o w i n g R o c q / C o q s t a t e m e n t :
25
26 ‘ ‘ ‘ R o c q
27
28 $ { f o r m a l _ s t a t e m e n t }
29 ‘ ‘ ‘
30 I t c o r r e s p o n d s t o t h e f o l l o w i n g i n f o r m a l s t a t e m e n t : ‘ ‘ ‘ $ { i n f o r m a l _ s t a t e m e n t } ‘ ‘ ‘
31
32 P l e a s e u s e C o q / R o c q a n d e n c l o s e t h e p r o o f i n t r i p l e b a c k t i c k s .
33
34 A s a n e x a m p l e , i f t h e s t a t e m e n t t o p r o v e i s
35
36 ‘ ‘ ‘ R o c q
37 T h e o r e m e x a m p l e ( a b : n a t ) ( h : a = b + 1 ) : a > b .
38 ‘ ‘ ‘
39
40 t h e n y o u r f i n a l p r o o f s n i p p e t s h o u l d f o l l o w t h i s f o r m a t :
41
42 ‘ ‘ ‘ R o c q
43 F r o m S t d l i b R e q u i r e I m p o r t L i a .
44
45 T h e o r e m e x a m p l e ( a b : n a t ) ( h : a = b + 1 ) : a > b .
46 P r o o f .
47 r e w r i t e h .
48 l i a .
49 Q e d .
50 ‘ ‘ ‘
51 T h e l a s t ‘ R o c q ‘ c o d e b l o c k w i l l b e p a r s e d a s y o u r f i n a l p r o o f .
52 c o n t r i b u t e : [ l o g g e r , c o n t e x t ]
Figure 23: PPDL program for MiniF2F benchmark (Part 1: initialization and prompt).
1 - r e p e a t :
2 t e x t :
3 - t e x t : |
4
5 [ $ { p d l _ p a r t i c l e _ i d } ] I T E R A T I O N : $ { i }
6
7 c o n t r i b u t e : [ l o g g e r , s t d o u t , s t d e r r ]
8 - m o d e l : $ { m o d e l _ p a r a m s [ ” m o d e l _ i d ” ] }
9 p a r a m e t e r s : $ { m o d e l _ p a r a m s }
10 d e f : r e a s o n i n g
11 c o n t r i b u t e : [ c o n t e x t , r e s u l t , l o g g e r ]
12 - d e f s :
13 r e s p o n s e :
14 d a t a : $ { r e a s o n i n g }
15 p a r s e r :
16 r e g e x :
17 ( . | \ n ) * ‘ ‘ ‘ ( c o q | C o q | r o c q | R o c q | ) \ n ( ? P < r o c q > ( . | \ n ) * ? ) ‘ ‘ ‘ ( . | \ n ) *
18 s p e c : { r o c q : s t r i n g }
19 i f : $ { r e s p o n s e = = N o n e }
20 t h e n :
21 d e f s :
22 r e s p o n s e :
23 d a t a :
24 r o c q : $ { f o r m a l _ s t a t e m e n t }
25 - d e f s :
26 r e s u l t :
27 l a n g : p y t h o n
28 c o d e : r e s u l t = c h e c k e r . c h e c k ( r e s p o n s e [ ” r o c q ” ] )
29 p r o m p t :
30 m a t c h : $ { r e s u l t [ ” s t a t u s ” ] }
31 w i t h :
32 - c a s e : E r r o r
33 t h e n :
34 l a s t O f :
35 - t e x t : |
36
37 P R O O F E R R O R - A t t e m p t i n g t o f i x $ { n a m e } . . .
38 c o n t r i b u t e : [ l o g g e r , s t d o u t ]
39 - f a c t o r : - 1
40 - t e x t : |
41 Y o u r p r e v i o u s R o c q / C o q p r o o f f a i l e d t o c o m p i l e w i t h t h e s e v e r i f i e r
42 e r r o r s :
43
44 $ { r e s u l t [ ” e r r o r ” ] }
45
46 P l e a s e f i x y o u r p r o o f .
47 c o n t r i b u t e : [ l o g g e r , r e s u l t ]
48 t o k e n s :
49 l a n g : p y t h o n
50 c o d e : |
51 r e s u l t = p d l _ u s a g e . c o m p l e t i o n _ t o k e n s + p d l _ u s a g e . p r o m p t _ t o k e n s
52 t e x t : $ { p r o m p t }
53 u n t i l : $ { ( r e s u l t [ ” s t a t u s ” ] = = ” C o m p l e t e ” ) o r ( t o k e n s > a g e n t _ p a r a m s [ ” m a x _ t o k e n s ” ] ) }
54 m a x I t e r a t i o n s : $ { a g e n t _ p a r a m s [ ” m a x _ d e p t h ” ] }
55 i n d e x : i
Figure 24: PPDL program for MiniF2F benchmark (Part 2: proof/repair loop).
1 - t e x t : |
2
3 D o u b l e - c h e c k i n g p r o o f c o r r e c t n e s s f o r $ { n a m e } . . .
4 C u r r e n t s t a t u s : $ { r e s u l t [ ” s t a t u s ” ] }
5
6 c o n t r i b u t e : [ l o g g e r , s t d o u t ]
7 - d e f s :
8 v e r i f i c a t i o n :
9 l a n g : p y t h o n
10 c o d e : r e s u l t = c h e c k e r . v e r i f y _ p r o o f ( n a m e , f o r m a l _ s t a t e m e n t , r e s p o n s e [ ” r o c q ” ] )
11 - t e x t : |
12
13
14 P R O O F $ { ” C O M P L E T E ” i f v e r i f i c a t i o n [ ” s t a t u s ” ] = = ” C o m p l e t e ” e l s e ” F A I L E D . ” }
15
16 S t a t u s : $ { v e r i f i c a t i o n [ ” s t a t u s ” ] }
17 G o a l : $ { f o r m a l _ s t a t e m e n t }
18
19 P r o o f :
20 ‘ ‘ ‘ r o c q
21 $ { r e s p o n s e [ ” r o c q ” ] }
22 ‘ ‘ ‘
23
24 c o n t r i b u t e : [ l o g g e r , s t d o u t ]
25 - d e f s :
26 r e s u l t :
27 d a t a :
28 s t a t u s : $ { v e r i f i c a t i o n [ ” s t a t u s ” ] }
29 p r o o f : $ { r e s p o n s e [ ” r o c q ” ] }
30 s t e p s : $ { i + 1 }
31 l a n g : p y t h o n
32 c o d e : |
33 i f ( v e r i f i c a t i o n [ ” s t a t u s ” ] = = ” C o m p l e t e ” ) :
34 r e s u l t s . a p p e n d ( ( r e s u l t , p d l _ u s a g e ) )
35 r a i s e E x c e p t i o n ( ” s u c c e s s ” )
36 c o n t r i b u t e : [ r e s u l t , l o g g e r ]
Figure 25: PPDL program for MiniF2F benchmark (Part 3: verification and result collection).
F. Case Study: Theorem Proving in Rocq
We presents additional results for the case study.
Figure 26: Number of MiniF2F-Rocq problems solved as a function of proof/repair steps. Each curve shows the mean over three runs, with shaded regions indicating one standard deviation.
Figure 26 shows the number of problems solved as a function of proof/repair steps for IS depending on the number of particles. It follows the same trends as SMC (see Figure 6).
Figure 27: Number of MiniF2F-Rocq problems solved as a function of the number of tokens.
Figure 27 shows the number of MiniF2F-Rocq problems solved as a function of the number of tokens. IS and SMC consume k times more tokens to prove the first theorem because they run k particles in parallel, but catch up with the IS@1 strategy which can only explore one trajectory. So the more we increase the token budget, the more the probabilistic approaches are beneficial.