liveBook · Manning

Natural language interface

As explained in Data Analysis with LLMs

A natural language query interface converts questions expressed in human language into database queries and returns answers from the queried data.

A natural language interface lets people ask questions about data in everyday language. A language model translates each question into a formal query, a data-processing tool runs that query, and the resulting data answers the question. section 5.1

A practical interface connects four pieces:

  • Input: the user’s question, such as “How many games did Activision create?” section 5.2.5
  • Instructions: a prompt identifies the target query language and describes the database structure, including tables, columns, and data types. section 5.1
  • Translation: the language model produces SQL for relational data or Cypher for graph data. section 5.1
  • Execution: a specialized database tool runs the query and returns the answer. section 5.1

From a question to an answer

For a games database, a user can ask, “How many games are stored in total?” The interface generates `SELECT COUNT(*) FROM games;` and returns `(16599,)`. It can continue accepting questions without restarting, execute each translated query, and display both the query and its answer. Because translation can be incorrect, the program catches database errors instead of terminating. section 5.3.4 section 5.3.3

Figure 5.1 A natural language query interface translates questions in natural language into formal queries, taking into account the data structure. Formal queries are then processed on data by a specia- lized tool, generating a query result.
figure

Follow the workflow from a natural-language question through formal query generation and specialized data processing to a query result. section 5.1

How Data Analysis with LLMs covers it

How deep it goes
Explains prompts, translation, extraction, execution, interactive looping, and error handling, but not language-model internals.
Examples
Uses a video-game sales database, questions about games and publishers, generated SQL, returned counts, and grouped genre results.
What it assumes
Assumes basic Python and some SQL for verification while teaching prompt construction, schema description, translation, and execution.
What you can do after
Build it from scratch as a Python interface that prompts a language model, extracts SQL, executes queries, and handles database errors.
How it connects
Links natural-language questions with SQL, Cypher, relational databases, graph databases, prompts, and language models.

Also explained in

Compare how 6 books explain natural language interface →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Analysis with LLMs. The section links point to the parts of the book it draws on.