Programming by Example (PBE) is a program synthesis paradigm where the specification is provided as a set of concrete input-output pairs. The system's core task is to infer a general program—often in a Domain-Specific Language (DSL)—that correctly produces the given outputs from the corresponding inputs. This approach is highly accessible, allowing users without programming expertise to automate repetitive data transformation tasks, such as formatting text or cleaning spreadsheets, by simply demonstrating a few desired corrections.
Glossary
Programming by Example (PBE)

What is Programming by Example (PBE)?
Programming by Example (PBE) is a subfield of program synthesis where the system infers a general program from a set of concrete input-output demonstrations.
The technical challenge in PBE is searching a vast space of possible programs for one consistent with all examples. Solvers use techniques like enumerative search, constraint solving, and version space algebra to efficiently prune possibilities. A canonical industrial application is Microsoft Excel's FlashFill. PBE is closely related to program induction and often employs Oracle-Guided Synthesis, where the user interactively provides new examples to refine the result, bridging the gap between demonstration and a robust, executable script.
Core Characteristics of Programming by Example
Programming by Example (PBE) is a program synthesis paradigm where the specification is provided as a set of concrete input-output pairs, and the system infers a general program that satisfies all examples. Its core characteristics define its unique approach to automating code creation.
Specification via Examples
The fundamental input to a PBE system is a specification provided as a set of concrete input-output pairs. Unlike formal logic or natural language, the user demonstrates the desired transformation with specific instances. The system's core challenge is to generalize from these finite examples to a program that works for all unseen inputs conforming to an implicit pattern. This makes PBE highly accessible, as users need no formal specification language.
- Example: In a spreadsheet, a user provides
"John Doe" -> "Doe, J."and"Jane Smith" -> "Smith, J.". - Goal: The synthesizer infers a program that extracts the last name, adds a comma, and appends the first initial for any similar full name input.
Search in a Constrained Space
PBE is fundamentally a search problem over the space of all possible programs. To make this tractable, synthesis is performed within a Domain-Specific Language (DSL). The DSL provides a limited set of primitives (e.g., string functions like Concat, Substring, Replace) and composition rules, which constrains the search to plausible, efficient programs for the target domain.
- Key Mechanism: The synthesizer uses deductive search, enumerative search, or constraint solving to explore the DSL-defined space.
- Benefit: This ensures generated programs are usable and efficient within their domain, such as data transformations in Excel or shell script commands.
Ranking and Disambiguation
Given a finite set of examples, there are often many candidate programs that satisfy them. PBE systems employ a ranking function or Occam's razor principle to select the simplest, most likely program intended by the user. This is critical for user intent disambiguation.
- Common Heuristics: Prefer shorter programs, programs using more familiar operators, or programs that generalize in predictable ways.
- Example: For examples
"cat" -> "c"and"dog" -> "d", bothfirst characterandremove all but first characterare valid. Ranking selects the simpler, more intuitivefirst characterfunction.
Interactive Refinement Loop
PBE is typically an interactive, human-in-the-loop process. The user provides initial examples, the system proposes a program, and the user can refine the specification by:
- Providing additional positive examples to clarify the pattern.
- Providing negative examples (counterexamples) to rule out incorrect generalizations.
- Directly editing the output for a new input, creating a new input-output pair. This iterative refinement loop is central to systems like Microsoft Excel's FlashFill, allowing users to quickly converge on the correct program through collaboration with the synthesizer.
Connection to Inductive Programming
PBE is a form of inductive programming, where a general rule (the program) is inferred from specific observations (the examples). This contrasts with deductive synthesis, which derives a program from a complete formal specification. The inductive nature introduces the generalization challenge: the system must hypothesize a program that works for the infinite set of inputs implied by the finite examples without overfitting to the provided instances. Techniques from machine learning, such as learning decision trees or using version space algebras, are often applied to manage this hypothesis space.
Primary Application Domains
PBE excels in domains where tasks are repetitive, rule-based, and easily demonstrated. Its major applications include:
- Data Wrangling & Transformation: Synthesizing string manipulations, column splits, and format conversions in tools like Trifacta Wrangler or Microsoft Excel's FlashFill.
- Shell Script & Regular Expression Synthesis: Generating command-line pipelines or regex patterns from example text matches.
- UI Automation: Inferring macros or scripts from user demonstrations of graphical interface interactions.
- Educational Tools: Helping novices learn programming concepts by showing the code that corresponds to their actions. The success in these areas stems from PBE's ability to turn demonstrative intent into executable code without requiring programming expertise.
How Programming by Example Works
Programming by Example (PBE) is a paradigm of program synthesis where the system infers a general program from a set of concrete input-output demonstrations.
Programming by Example (PBE) is a program synthesis technique where the user specifies desired behavior by providing concrete input-output pairs, and the system automatically infers a general program that satisfies all given examples. This approach transforms a specification-by-demonstration into executable code, such as a string transformation in a spreadsheet or a data-wrangling script, without requiring the user to write formal logic or code. The core challenge is the ambiguity of examples; many possible programs can fit the same few data points.
The synthesizer resolves this ambiguity through a search-and-verify loop. It searches a space of programs defined by a Domain-Specific Language (DSL) for candidates that produce the correct outputs for all given inputs. Advanced systems like FlashFill use deductive reasoning and constraint solving to efficiently prune the search. To ensure the generated program generalizes correctly, the system may propose new counterexamples for the user to label, a process known as interactive synthesis or oracle-guided synthesis.
Frequently Asked Questions
Programming by Example (PBE) is a core technique in program synthesis that enables users to generate executable code by providing concrete demonstrations of the desired behavior. This FAQ addresses common technical questions about its mechanisms, applications, and relationship to other AI paradigms.
Programming by Example (PBE) is a program synthesis paradigm where the system infers a general, executable program from a set of concrete input-output pairs provided by the user. It works by treating the examples as a specification and searching a constrained space of possible programs, defined by a Domain-Specific Language (DSL), for one that produces the correct outputs for all given inputs. The core technical challenge is search space explosion; solvers use techniques like version space algebra, Satisfiability Modulo Theories (SMT), or neural-guided search to efficiently find a candidate program that generalizes correctly beyond the provided examples.
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
Programming by Example (PBE) is a specific paradigm within the broader field of program synthesis. These related terms define the adjacent techniques, frameworks, and applications that share its goal of automatically generating executable code.
Program Synthesis
The overarching field of automatically generating executable code from a high-level specification. PBE is a specific subfield where the specification is a set of input-output examples. Other specification types include:
- Natural language descriptions
- Formal logical constraints
- Partial programs (sketches)
- Reference implementations (for translation) The core challenge is searching the vast space of possible programs for one that satisfies the given spec.
FlashFill
A landmark Programming by Example (PBE) system developed by Microsoft Research and integrated into Excel. It synthesizes string transformation programs from user-provided examples in adjacent spreadsheet cells.
- Domain: Primarily text/string manipulation (e.g., formatting names, extracting substrings).
- Mechanism: Uses a Domain-Specific Language (DSL) for string operations and efficient search algorithms to find the simplest program consistent with all examples.
- Impact: Demonstrated the commercial viability of PBE, automating repetitive data-wrangling tasks for millions of users.
Sketch-Based Synthesis
A synthesis technique where the user provides a partial program (a sketch) containing "holes" (placeholders for missing code fragments). The synthesizer's task is to fill these holes with concrete code to satisfy a formal specification.
- Key Difference from PBE: The user provides structural guidance (the sketch), reducing the search space compared to pure example-based synthesis.
- Use Case: Common in systems programming and performance optimization, where the programmer knows the overall algorithm but needs help with low-level details or bit-precise operations.
Counterexample-Guided Inductive Synthesis (CEGIS)
A powerful algorithmic architecture for synthesis, especially with formal specifications. It operates in a loop:
- Inductive Synthesis: Generates a candidate program that works for a finite set of examples.
- Verification: Checks if the candidate satisfies the full formal spec.
- Counterexample Generation: If verification fails, a counterexample (an input where the output is wrong) is produced.
- Refinement: The counterexample is added to the set of examples, and the loop repeats. This bridges machine learning (learning from examples) and formal methods (guaranteeing correctness).
Neural Program Synthesis
Uses deep learning models (e.g., sequence-to-sequence networks, transformers) to generate code. Unlike classical PBE which relies on logical search, neural synthesis learns probabilistic patterns from large corpora of code and specifications.
- Inputs: Natural language, examples, or partial code.
- Models: Architectures like Codex, CodeT5, or Code Llama.
- Relation to PBE: Can be used to implement PBE by training on input-output pairs, but typically lacks the formal guarantees of classical synthesis. Often used for exploration (proposing candidate programs) within a larger synthesis framework.
Program Synthesis for Data Wrangling
A major application domain for PBE and related techniques. It automates the tedious process of cleaning and transforming raw data into an analysis-ready format.
- Common Tasks: Synthesizing Pandas transformations, SQL queries, regular expressions, or file format converters.
- Specification: Often provided as input-output examples on a small data sample.
- Tools: Modern platforms like Trifacta and OpenRefine incorporate synthesis ideas to suggest data transformation scripts based on user actions and examples.

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