Local LLMs in industry: why text-to-SQL is more than a modelling problem
A master’s thesis at Dürr examines how database structure, business context and system design affect the reliability of locally hosted text-to-SQL systems.
Jan Kirenz · · 10 min read
Many companies want to use generative AI in day-to-day operations. One example is text-to-SQL, where a system translates a question in everyday language into a database query. Privacy, security or infrastructure requirements can rule out cloud models. In that case, choosing a model that runs locally is only the first step. Can the system translate questions into reliable database queries and return answers that people can trust under real operating conditions?
Aaron Stark explored this question in his master’s thesis, which I supervised together with Dr Jannis Hanke of Dürr Systems AG (DXQ Analytics and AI). The thesis investigated how local large language models (LLMs) could help analyse structured process data. The test case came from industrial paint shops. Could users ask questions in their own words about process statistics and alarms? Stark built a prototype and evaluated it systematically.

The prototype’s architecture for analysing industrial process data through natural-language questions.
The study compared the performance of several local models. It also showed how much an industrial text-to-SQL test reveals about the system as a whole. Architecture, context, domain knowledge and data structures interact more closely than discussions of generative AI often suggest.
What makes industrial text-to-SQL different?
Text-to-SQL sounds straightforward. A user asks a question, the system generates a SQL statement, runs it and returns an answer. It often works well in demonstrations with a small, well-documented data model. Yet studies of text-to-SQL on real company databases show that production data poses problems that benchmark schemas rarely capture. Nascimento et al., 2025, Sun et al., 2023
Industrial data comes from distributed sources and operational databases. It reflects specialised business rules and structures that have evolved over many years. Research on schema linking and breaking down complex questions points to the same conclusion. As the underlying data becomes more diverse, the quality of the preparation has more influence on whether a query executes correctly. Wang et al., 2025, Pradeep et al., 2025
Five factors mattered in this case.
- The data was spread across several sources.
- The system had to interpret different kinds of databases together, including databases for process statistics and alarms.
- The schemas were designed for operational storage, which made them difficult for an LLM to interpret.
- The system had to map specialist terms, station names and rules about time to the correct database structures.
- Many questions required aggregation, calculation and domain-specific interpretation as well as SQL generation.
What the system could do depended on the model, the structure of the data, the context the model received, the tools it could call and the way those parts worked together.
What the thesis investigated
The prototype handled natural-language questions about structured industrial data stored in SQL databases. It went through two iterations. The first used a relatively simple multi-agent architecture. In the second, Stark added components to address specific weaknesses. These included a calculator agent for deterministic calculations and a synthesiser agent that organised the results into an answer. Other research on multi-agent text-to-SQL systems has also found that dividing the work explicitly can offer advantages over a single model handling every step. Heidari et al., 2025

The architecture separates routing, data retrieval, calculation and answer synthesis.
The changes between the two versions help explain the results. A generative AI system intended for operational use can improve when each component has a clear responsibility and the architecture specifies how the model, tools and data-processing rules work together.
How the division of work affected the results
Running a large model locally does not, by itself, make a system useful. In this case, the architecture was a major constraint.
In the first iteration, individual agents had too many jobs. An agent might have to interpret the question, distinguish between data sources, generate SQL, aggregate intermediate results and write the answer. Local models were particularly sensitive to that workload. They made poor use of their context windows, called tools inconsistently and made more numerical errors.
Separating routing, retrieval, calculation and answer synthesis made the system more stable. Models that had performed poorly in the first version benefited most from the second. Architecture had more influence on answer quality than either model size or the degree of quantisation. For a company planning to run AI locally in an operational setting, that gives system architecture and workflow design a place early in the discussion.
Why context engineering matters
The thesis illustrates a pattern seen in many generative AI projects. The quality of a single prompt explains only part of the result. The way the system prepares domain and technical context makes a substantial difference. Recent research also treats context engineering as a discipline in its own right. Mei et al., 2025, Hua et al., 2025
In this case, reliable SQL generation required clearly defined agent roles, a few worked examples, mappings for specialist terms, explicit constraints and schema linking to connect a user’s question to the relevant database structures.
Some of this resembles prompt engineering. The wider task is to connect the meaning of a business question to a database schema. A model can understand the words in a question and still lack the context to identify the right data.
A term that is unambiguous to someone working in a paint shop may have no obvious match in the database. The mappings and examples in this project emerged from close collaboration with domain experts. That work made context engineering part of the system design from the outset.
Where deterministic tools belong
Questions about totals, averages and aggregations across databases expose a practical limit of language models. A numerical answer can sound plausible even when the arithmetic is wrong.
The prototype delegates calculations to a dedicated calculator agent that uses deterministic tools. The same calculation then follows the same rules each time, reducing the scope for interpretation and making the result more reliable.
Language models are well suited to understanding a question, organising information and writing an answer. Calculations, multi-step aggregations and transformations that affect operational decisions are less reliable when the model performs them itself. A production system should use deterministic processing for these tasks wherever possible.
The thesis also identifies a further option. Where the data structure permits it, the database can perform the calculations directly.
What the evaluation showed about local models
The evaluation used a reference dataset of 33 test scenarios of varying complexity. It compared several local models against a cloud-based reference model.
The local models could translate natural-language questions into SQL and deliver usable results in a well-defined setup. This supported the thesis’s starting assumption that industrial analytics is a plausible application for local LLMs.
The prototype’s answers still fell short of the quality needed in production. Using local models accounted for only part of the gap. Complex questions, questions combining several tasks and numerically demanding queries exposed weaknesses in how the architecture, tool use, context preparation and data structures worked together. Larger models did not consistently produce better results, and quantisation did not adequately explain the differences either.
For practical deployments, it matters how well a model performs on the available hardware, within the chosen agent workflow and with the context it actually receives. On the infrastructure in this study, models with fewer than 40 billion parameters offered a workable balance between answer quality, response time and hardware requirements.
How database design affects the system
A finding that emerged alongside the model comparison concerned the structure of the databases themselves.
When data is distributed across sources, highly normalised and difficult to query for analysis, the whole system becomes more complex. Prompts get longer, more tooling is required, context windows fill up and errors become more likely. A failure that appears to originate in the model can often be traced to the data structure.
The thesis recommends bringing the data into a central structure that supports analytical queries and that an LLM can interpret. For a company considering text-to-SQL, this brings data modelling, extract-transform-load (ETL) processes and the design of the analytical database into the same discussion as models and frameworks.
In this setting, decisions about AI strategy and data architecture are closely connected.
Questions for companies considering text-to-SQL
Many generative AI projects begin by asking which model to use. The thesis points to a second set of questions that matters more as a system moves closer to production.
- What architecture does this use case require?
- Which tasks can the model handle, and which belong in other components?
- What context does the model need to interpret questions correctly in this domain?
- Which data structures introduce unnecessary complexity?
- How can the team evaluate quality systematically?
Connecting an LLM to an industrial database is only a starting point. The system also needs a sound design, input from domain experts and an evaluation method with explicit criteria. The thesis used its reference dataset to assess both the answers and the routes the system took to reach them. It used the LLM-as-a-judge approach, which uses a language model to evaluate results and has attracted considerable research interest. Li et al., 2024
Practical recommendations
The findings suggest five recommendations that apply beyond this case.
- Design the architecture before choosing the model. Agent responsibilities, tool use, routing and fault tolerance often matter more than access to the latest model.
- Delegate deterministic work. Use dedicated tools for calculations, aggregation and processing steps where an error would affect an operational decision.
- Build domain context into the system. Specialist terms, database logic, worked examples and schema mappings are part of the product.
- Prepare the data for analytical queries. Distributed operational databases rarely provide a suitable long-term foundation for a reliable text-to-SQL system.
- Evaluate realistic scenarios. A reference dataset with clear expected answers is essential for assessing a system intended for production.
Conclusion
Aaron Stark’s thesis shows what it takes to use local LLMs in an industrial setting. The outcome depends on how architecture, context, data structures, expert knowledge and deterministic components work together.
The findings are relevant beyond industrial paint shops. They identify conditions under which local LLMs can be useful in sensitive industrial environments, while also showing where the tested system still fell short of production requirements. They offer a more qualified account of the role of local AI than a claim that it can replace the cloud.
Source
- Aaron Stark (2026). Entwurf und Evaluation eines Prototyps zur Analyse industrieller Prozessdaten unter Einsatz lokaler Large Language Models [Design and evaluation of a prototype for analysing industrial process data using local large language models]. Unpublished master’s thesis, Stuttgart Media University, in collaboration with Dürr.
Further reading
- Nascimento et al. (2025). LLM-Based Text-to-SQL for Real-World Databases
- Wang et al. (2025). LinkAlign: Scalable Schema Linking for Real-World Large-Scale Multi-Database Text-to-SQL
- Pradeep et al. (2025). Divide, Link, and Conquer: Recall-oriented Schema Linking for NL-to-SQL via Question Decomposition
- Heidari et al. (2025). AGENTIQL: An Agent-Inspired Multi-Expert Framework for Text-to-SQL Generation
- Mei et al. (2025). A Survey of Context Engineering for Large Language Models