Semantic parsing

On this page 7

Semantic parsing is the task of mapping a natural language utterance to a formal meaning representation that a machine can execute or reason over, such as a SQL query, a lambda-calculus expression, a knowledge graph query or a structured API call. Within speech & language AI, it is the bridge between what people say and what software does, and in artificial intelligence more broadly it is a core technique for grounded language understanding.

Unlike tasks that label words or classify whole sentences, semantic parsing produces a complete structured program. The output is judged by whether it is correct and executable: the question “Which flights leave Boston after 6 pm?” must become a query that returns exactly the right rows from a database.

How semantic parsing turns language into executable meaning

A semantic parser takes an utterance and, often, a schema or environment description, and outputs an expression in a target formal language. The process involves recognizing entities, resolving them against the schema, identifying predicates and relations, and composing these pieces according to the compositional structure of the sentence.

Compositionality is the defining principle: the meaning of the whole is built from the meanings of the parts and the way they combine. The phrase “cheapest flight to Denver” combines a superlative operator, an entity type and a destination constraint, and a good parser composes them into a single coherent expression rather than matching templates.

The target formalism shapes the whole system. The following table lists common meaning representations and their typical uses.

RepresentationTypical useExecution environment
SQLQuestions over relational databasesDatabase engine
SPARQLQuestions over knowledge graphsGraph or triple store
Lambda calculusFormal semantics researchLogical inference engine
Abstract Meaning RepresentationBroad-coverage sentence meaningNot directly executable
API calls or codeAssistants and tool useApplication or interpreter
Common target meaning representations

From grammar-based to neural semantic parsers

Semantic parsing methods have moved through three broad generations. Early systems used hand-written grammars and rules that were precise in narrow domains but brittle. Statistical parsers based on combinatory categorial grammar learned lexicons from data and improved coverage while keeping explicit compositional structure.

Neural sequence-to-sequence models then treated parsing as translation from text to a linearized logical form. Grammar-constrained decoders improved validity by generating abstract syntax trees rather than raw tokens. Today, large language models prompted with the schema and a few examples, or fine-tuned on paired data, dominate text-to-SQL and tool-calling benchmarks.

ApproachHow it worksStrengthWeakness
Rule and grammar systemsHand-built lexicon and rulesPredictable, auditable outputPoor coverage of paraphrases
Statistical CCG parsersLearned lexicon with grammarExplicit compositional structureNeeds feature engineering
Neural seq2seqEncoder-decoder over textHandles varied phrasingMay produce invalid output
Grammar-constrained decodingGenerates valid syntax treesGuaranteed well-formed outputMore complex implementation
Large language modelsPrompted or fine-tuned generationStrong cross-domain transferHallucinated columns, cost
Generations of semantic parsing methods

Semantic parsing overlaps with several neighboring tasks but differs in the depth and executability of its output. Intent recognition and slot filling produce a flat frame, while semantic parsing can express nested operations, aggregation, negation and comparison.

TaskOutputExecutableHandles nesting
Semantic parsingFull logical form or programYesYes
Intent recognition with slot fillingIntent label plus slot valuesPartlyRarely
Semantic role labelingPredicate-argument rolesNoLimited
Dependency parsingSyntactic head-dependent treeNoSyntactic only
Question answeringAnswer text or spanNot requiredImplicit
Semantic parsing and neighboring tasks

Syntactic parsing describes grammatical structure, not meaning, so it is often an input feature rather than a substitute. Many production assistants combine a lightweight intent classifier for simple commands with a full semantic parser for complex queries.

Evaluating and deploying semantic parsers

Evaluation uses two complementary metrics. Exact match accuracy compares the predicted expression with the reference, while execution accuracy runs both and compares results. Execution accuracy forgives harmless differences such as column order, but it can also reward spurious programs that return the right answer for the wrong reason.

Well-known benchmarks include GeoQuery and ATIS for early domain-specific work, Spider and BIRD for cross-database text-to-SQL, and WebQuestions for knowledge base questions. Cross-domain benchmarks matter because real deployments face unseen schemas, where memorized table names do not help.

Deployment adds requirements that benchmarks rarely measure. Latency budgets limit how many candidate programs a system can sample and verify, and schema drift means that renamed columns or new tables silently degrade accuracy unless descriptions are kept current. Teams therefore maintain a regression suite of real questions with verified answers and rerun it after every model, prompt or schema change.

Interactive designs also improve reliability. A parser that explains its interpretation in plain words, or offers two candidate readings of an ambiguous request, lets users catch errors before they act on wrong numbers, which matters more in business settings than a few points of benchmark accuracy.

  • Schema linking: map words like “revenue” to the correct column before generation.
  • Constrained decoding: reject outputs that reference nonexistent tables or fields.
  • Execution checks: run the query in a sandbox and retry on errors.
  • Read-only permissions: never let generated queries modify production data.

Limitations and common failure modes

Semantic parsers fail most often on ambiguity and compositional generalization. Questions such as “top customers last quarter” hide choices about ranking metric and calendar boundaries, and models trained on simple combinations often break on novel combinations of familiar parts, a weakness exposed by datasets designed for systematic generalization.

Large language models add the risk of plausible but wrong programs: a syntactically valid query that joins the wrong tables returns confident numbers. Collecting training data is also expensive, because annotators must know both the domain and the formal language. Robust systems therefore show the generated query to users or ask clarifying questions when confidence is low.

In simple terms

Computers do not understand ordinary sentences. They follow exact instructions. Semantic parsing is the translator between the two.

Suppose you ask, “How many orders did we ship last week?” A semantic parser rewrites that question as a precise command for a database. The database runs it and returns a number. The key point is that the output is a runnable instruction, not a summary or a guess. If the translation is wrong, the answer will be wrong too, even if it looks convincing.

A practical example

A regional retailer wants store managers to query sales data without learning SQL. The analytics team builds a text-to-SQL assistant over a warehouse with 60 tables, giving the language model a curated schema description, column synonyms and 40 verified question-query pairs as examples.

Each generated query passes through schema validation and a read-only sandbox before execution, and the assistant displays the query alongside the result. When a question is ambiguous, such as “best stores this month,” the system asks whether “best” means revenue, margin or unit sales.

After a three-month pilot with 120 managers, the team measures execution accuracy of roughly 90 percent on a held-out set of real questions, and ad hoc report requests to analysts fall by about half. Remaining errors concentrate on fiscal calendar logic, which the team addresses by adding a dedicated date dimension description to the prompt.