All articles
  • Absolute Intelligence
  • LISSA
  • Data analysis

Robotic caseworker - generating documents with an LLM

5 minute read

In practice we often need to create a document from some inputs, where the resulting document must have a predefined structure and contain both the correct formalities and factually correct information from the inputs provided. An example is an application for a building permit. An official checks the application (whether it meets the formal requirements and contains all the required data), studies the documents and produces a decision containing the information from the application.

Summary

  • A robotic caseworker uses an LLM to prepare, from the documents provided, a draft of a document with a predefined structure, for example a decision in administrative proceedings.
  • Prompt chaining has proved best: the system extracts structured data from the text and offers questions from which the user chooses.
  • The tool, still a prototype, processes uploaded documents according to the chosen template within minutes, and the user only checks the draft and edits it if needed.

We already meet similar requests from customers. At the Foreign Police department of the Police of the Czech Republic, for example, it is very common for an officer to have a whole range of documents as source material (the record of a person's questioning, case files from a court, employment records, hearings of the parties to the proceedings), from which they must draw up, in administrative proceedings, a decision that complies with the Administrative Procedure Code and contains the factual data from the input documents.

In terms of time, this is a fairly demanding activity: the user has to study all the files and documents, extract the necessary information from them and gradually compose a document containing it.

It seems obvious that, with the arrival of large language models, this activity could be partly or fully automated. Our first thought was to use simple summarisation of the documents to generate part of the text of the decision automatically. This turned out not to be very suitable, because the result lacked some essential data from the input documents, and the system also fairly often judged some data to be relevant when it was not. We also considered a combination of text summarisation and fine-tuning the language model, teaching it on many cases what the output text looks like and using these methods to get closer to the right result.

In the end we achieved a significantly better result by prompt chaining, where we divided the whole task into individual steps and built up the content of the target document step by step:

  • The first part of the task is in fact function calling, where we extract structured data from the text, such as first name, surname, date of birth, passport number, address, telephone number and e-mail address.
  • The next part of the process is to define the key parts of the document, or better said the essential ones, containing important information that must appear in the resulting document. Here, as in all similar cases, we run into an interesting problem with composing the query, the prompt. The prompt is a very important element of language models and affects the result substantially. For each individual case the prompt has to be tuned so that the resulting answer is factually correct and contains the required information.
  • In the following steps a summary is offered: a list not of key information but, in effect, of questions generated by the artificial intelligence. The user can choose which of these questions to use further and which to discard.

This approach, where the queries are prepared within the process, proves to be very useful and user-friendly at the same time. You in effect turn a complex query into a set of simpler prompts, and with a suitable technique you make sure the resulting text matches your needs exactly.

Behind the whole process there is of course a whole range of technical means for manipulating the content of the document, such as vectorising the content, storing the vector in a vector database, querying the vector database, processing documents when a document is too long, and so on. All large language models have some limit on the number of characters you can insert into the so-called context window, on the basis of which the language model prepares its output. If such a context file is too large, the language model may be unable to process it.

These technical matters all happen in the background of the system, so users of our solutions need not worry about them. Users simply prepare the input documents, upload them to the system and choose an output template. The system reads the input documents and proposes a set of questions in a list. From these the user selects the suitable ones and sends the document for processing. The output is a draft of the final document, which the user only checks and edits if needed, or goes back in the process and supplies any missing input information. Processing the documents then takes minutes, not days.

We are convinced of the considerable effectiveness of this tool, which is at the prototype stage. We are more concerned that users will rely fully on the system without paying enough attention to the creation of the final document.

Advantages of generating documents from a supplied text with an LLM:

  1. Speed and efficiency: an LLM can generate documents faster than a person, which saves time and resources.
  2. Consistency: an LLM can ensure that the resulting document has a consistent format and style, which makes it easier to read and understand.
  3. Personalisation: an LLM can be trained on specific patterns or templates, which makes it possible to create documents that meet specific requirements or standards.
  4. Flexibility: an LLM can easily be updated or adapted if the pattern or the requirements for the document change.
  5. Fewer errors: an LLM can reduce errors caused by the human factor, such as typos or grammatical mistakes.

Problems of generating documents from a supplied text with an LLM:

  1. Errors in the generated text: an LLM can generate incorrect or inappropriate information if it is not trained properly or does not receive sufficiently clear instructions.
  2. Context and semantics: an LLM can have difficulty understanding the context or semantics of the supplied text, which can lead to incorrect formatting or structural errors.
  3. Limits set by the training data: if an LLM was not trained on sufficiently relevant data, it can have problems generating documents that are meant to meet specific requirements or standards.
  4. Misinterpretation: an LLM can misinterpret the supplied text or “fail to understand” its purpose, which leads to documents that do not meet the requirements.
  5. Ethical and legal questions: using an LLM to generate documents can raise questions about the protection of personal data, intellectual property or responsibility for errors and inaccuracies in the generated texts.

Get in touch

A few sentences about what you are working on will help us prepare.

We describe how we handle personal data in our privacy policy.

You can also call us on +420 228 227 418 or email us at info@datera.cz.