Sketch-based synthesis is a program synthesis technique where a developer provides a high-level program outline, or sketch, containing intentional gaps ("holes") to be filled automatically. The synthesizer's task is to search for code fragments that, when inserted into these holes, produce a complete program that satisfies a formal specification, such as input-output examples or logical constraints. This approach balances user control with automation, guiding the search within a constrained space defined by the sketch's structure.
Glossary
Sketch-Based Synthesis

What is Sketch-Based Synthesis?
A technique for automatically generating executable code by completing a user-provided partial template.
The technique is foundational for building reliable autonomous agents and automated systems, as it translates partial intent into verifiably correct code. It is closely related to Syntax-Guided Synthesis (SyGuS) and often employs Satisfiability Modulo Theories (SMT) solvers or neurosymbolic methods to efficiently explore the solution space. By requiring a sketch, it reduces the combinatorial explosion inherent in synthesis from scratch, making it practical for generating complex, bug-free routines for data transformation, API orchestration, or hierarchical task network execution.
Key Components of a Sketch
A sketch is a partial program template that defines the program's high-level structure while leaving intentional gaps, or 'holes', for the synthesizer to fill. This breakdown details its core elements.
Program Skeleton
The program skeleton is the concrete, user-written code that forms the fixed structure of the sketch. It defines control flow (e.g., loops, conditionals), function signatures, and data types. This skeleton provides critical constraints that drastically reduce the search space for the synthesizer, guiding it towards a syntactically and semantically plausible solution. For example, a skeleton for a sorting function would explicitly define the function name, parameters, and a loop structure, leaving only the comparison and swap logic as holes.
Holes (Placeholders)
Holes (denoted by ?? or _ in tools like Sketch) are placeholders within the skeleton where code fragments must be synthesized. Each hole has an associated type (e.g., integer, boolean, list) and sometimes a grammar defining the set of allowed expressions. The synthesizer's core task is to find expressions of the correct type to fill these holes such that the complete program satisfies the specification. Holes can represent:
- Single expressions (e.g., a boolean condition
??in anifstatement). - Sequences of statements.
- Entire function bodies.
Specification
The specification is the formal or semi-formal description of the program's required behavior. It acts as the correctness criterion for the synthesized code filling the holes. In sketch-based synthesis, specifications are often provided as:
- Assertions and Pre/Post-conditions: Logical constraints within the skeleton (e.g.,
assert(sorted(arr))). - Reference Implementrations (oracles): A simpler, possibly inefficient, version of the function that defines correct behavior.
- Input-Output Examples: A set of concrete test cases the completed program must pass.
- Temporal Logic Formulas: For reactive systems, properties expressed in logics like LTL.
Grammar/Search Space Constraints
This component explicitly defines the set of possible code fragments that can be used to fill each hole. It is often specified via a context-free grammar or a set of component functions. For example, a hole for an integer expression might be constrained to the grammar: Expr := Constant | Variable | Expr + Expr | Expr * Expr. This constraint is critical for tractability; without it, the search space would be infinite. The grammar encodes domain knowledge, ensuring the synthesizer only explores relevant, efficient, or safe constructs.
Synthesis Engine & Solver
The synthesis engine is the algorithmic core that searches for valid hole completions. It typically reduces the problem to a constraint satisfaction problem. The engine:
- Encodes the skeleton, hole grammars, and specification into a system of logical constraints.
- Uses a Satisfiability Modulo Theories (SMT) solver like Z3 to find a satisfying assignment for the holes.
- Translates the solver's model back into concrete source code. This process often occurs within a Counterexample-Guided Inductive Synthesis (CEGIS) loop, where counterexamples from failed verification refine the constraints iteratively.
Related Concept: Syntax-Guided Synthesis (SyGuS)
Syntax-Guided Synthesis (SyGuS) is the standardized formal framework that underlies most modern sketch-based synthesis tools. It explicitly separates the three key components:
- A grammar defining the search space (the 'Syntax' guide).
- A logical specification (typically in first-order logic).
- The synthesis engine that solves the SyGuS problem. Sketch-based synthesis is a powerful instantiation of the SyGuS paradigm, where the user-provided skeleton and holes implicitly define a tailored grammar for the problem at hand. The SyGuS format enables competition and innovation among different solver backends.
How Sketch-Based Synthesis Works
A technical overview of the synthesis paradigm where a partial program template guides the automated search for a complete, correct implementation.
Sketch-based synthesis is a program synthesis technique where a developer provides a high-level program sketch—a partial template with intentional gaps called holes—and a formal specification. The synthesizer's role is to search the constrained space of possible code fragments to fill these holes, producing a complete program that provably satisfies the given specification. This approach balances user guidance with automated search, making synthesis tractable for complex problems by reducing the combinatorial search space.
The core technical mechanism involves encoding the sketch, specification, and a background theory (defining operations and their semantics) into logical constraints for a Satisfiability Modulo Theories (SMT) solver. The synthesizer queries the solver to find concrete expressions that, when placed into the sketch's holes, yield a valid program. Modern implementations often use a Counterexample-Guided Inductive Synthesis (CEGIS) loop, where candidate solutions are generated, checked against the specification, and refined using counterexamples from failed verification attempts.
Frequently Asked Questions
Sketch-based synthesis is a program synthesis technique where the user provides a partial program (a sketch) with holes, and the synthesizer automatically fills these holes with code fragments to satisfy a given specification. This FAQ addresses common technical questions about its mechanisms, applications, and relationship to other synthesis paradigms.
Sketch-based synthesis is a program synthesis technique where a developer writes a partial program template, called a sketch, containing intentional gaps or "holes" (denoted by ??), and an automated synthesizer fills these holes with concrete code fragments to produce a complete, correct program. The process works by combining a sketch with a formal specification (e.g., input-output examples, logical assertions, or a reference implementation). The synthesizer treats the holes as unknown constants or expressions and uses a constraint solver, typically a Satisfiability Modulo Theories (SMT) solver like Z3, to search for values that satisfy the specification. This transforms an open-ended search problem into a more constrained, and therefore more tractable, constraint satisfaction problem.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Sketch-based synthesis exists within a broader ecosystem of techniques for automatically generating executable code. These related concepts define the methodologies, tools, and formal frameworks that enable this automation.
Programming by Example (PBE)
A program synthesis paradigm where the user provides a set of concrete input-output pairs as the specification. The synthesizer's goal is to infer a general program that correctly produces the given outputs for all provided inputs. This is highly user-friendly but can be ambiguous.
- Key Feature: Specification is purely demonstrative.
- Example: Microsoft Excel's FlashFill feature, which learns string transformations from a few cell examples.
- Contrast with Sketching: PBE provides no structural hints, while a sketch provides a partial program template.
Counterexample-Guided Inductive Synthesis (CEGIS)
A powerful algorithmic loop that combines inductive generalization with formal verification. It iteratively:
- Synthesizes a candidate program consistent with current examples.
- Verifies the candidate against a formal specification using a solver.
- If verification fails, a counterexample (an input where the output is wrong) is extracted.
- The counterexample is added to the set of examples, and the loop repeats.
This technique is foundational for correct-by-construction synthesis and is often used to fill the holes in a program sketch.
Syntax-Guided Synthesis (SyGuS)
A standardized formal framework for program synthesis that defines the problem using two constraints:
- A context-free grammar (the
Synin SyGuS) that defines the space of allowed programs. - A logical specification (often in first-order logic) that defines correctness.
The synthesizer must find a program from the grammar that satisfies the logical spec. This provides a rigorous, solver-friendly formulation. Sketch-based synthesis can be seen as a SyGuS problem where the sketch defines a specialized grammar with holes.
Neurosymbolic Program Synthesis
A hybrid architecture that combines the strengths of neural networks and symbolic reasoning.
- Neural Component: Learns from ambiguous, high-level specifications (e.g., natural language, noisy examples) to propose likely program structures or priors.
- Symbolic Component: Uses logical constraints, formal verification (e.g., SMT solvers), and search to ensure the generated program is semantically correct.
This approach is particularly effective for sketch-based synthesis, where a neural model might suggest initial sketches or rank potential completions, while symbolic methods guarantee final correctness.
Type-Directed Synthesis
A synthesis methodology that leverages rich type systems—such as refinement types or dependent types—to constrain the search space. The types act as a lightweight formal specification.
- Mechanism: The synthesizer uses type inference and hole-filling to construct a program that inhabits a given target type.
- Example: Given a type signature
(x: {Int | x > 0}) -> {Int | result > x}, the synthesizer searches for a function that takes a positive integer and returns a larger integer. - Relation to Sketching: Types can be seen as a form of sketch, specifying the "shape" of the code without the implementation details.
Program Repair
A specialized form of program synthesis focused on automatically fixing bugs in existing code. Given a faulty program and a specification (e.g., failing test cases), the repair engine synthesizes a minimal patch.
- Common Approach: Treats the buggy code as a sketch, where the buggy region is a "hole" to be replaced with a correct fragment.
- Techniques: Often uses CEGIS or constraint-solving to generate and validate candidate patches.
- Contrast: While general synthesis builds from scratch, repair modifies an existing, mostly correct artifact, making the search space more targeted.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us