LLMStructBench2 is a dataset generation pipeline for evaluating how reliably language models can extract structured information from realistic workplace emails.
The project creates paired data:
Ground-truth JSON object ↔ Generated email
This allows controlled experiments on information extraction from realistic but synthetic workplace communication. Each use case defines its own schema, generation rules, email instructions, and validation logic.
Dataset: The released dataset is available on Hugging Face at HTW-KI-Werkstatt/LlmStructBench2. You only need this repository if you want to reproduce, inspect, or extend the pipeline that created it.
The dataset is published at https://huggingface.co/datasets/HTW-KI-Werkstatt/LlmStructBench2. It holds 6,054 emails rendered from 610 ground-truth objects in 8 business scenarios. Each object is rendered in up to 10 variants, which combine 5 length tiers with 2 formatting conditions (clean and messy).
import json
from datasets import load_dataset
emails = load_dataset("HTW-KI-Werkstatt/LlmStructBench2", split="test")
schemas = {
row["scenario"]: json.loads(row["json_schema"])
for row in load_dataset("HTW-KI-Werkstatt/LlmStructBench2", "schemas", split="test")
}
row = emails[0]
target = json.loads(row["ground_truth"])
schema = schemas[row["scenario"]]Every row carries id, object_id, scenario, length_tier, formatting, email_text, and the ground_truth as a JSON string. Each scenario is also available as its own subset, and the subset schemas holds the JSON schema of every scenario. See the dataset card on Hugging Face for the full description.
The published dataset is the cleaned run D5 of this pipeline (validation/cleaned/D5/). The intermediate outputs of that run are part of this repository, so every email can be traced back to its ground-truth object, its generation configuration, and its validation result.
LLMStructBench2 consists of four stages:
Ground Truth Generation gt-generator/
↓
Email Generation json-to-mail-generator/
↓
Validation validation/main.py
↓
Cleaning validation/clean.py
- Ground-truth generation creates structured JSON objects for each configured use case.
- Email generation converts these JSON objects into natural-sounding workplace emails, one per email configuration.
- Validation checks whether the generated emails still contain the required information in an extractable form.
- Cleaning removes or repairs the cases that failed validation and writes the cleaned dataset.
A separate module, dataset-eval/, evaluates the quality of the resulting dataset.
LLMStructBench2/
├── gt-generator/
│ ├── configurations/
│ │ ├── general.yaml
│ │ └── use-case/ (one .toml per use case)
│ ├── schemas/ (one JSON schema per use case)
│ ├── template/
│ │ ├── base.jinja
│ │ └── use-case/ (one .jinja per use case)
│ ├── utils/ (OpenAI adapter)
│ ├── output/
│ └── main.py
│
├── json-to-mail-generator/
│ ├── config/
│ │ ├── general.json (the ten email configurations)
│ │ └── use-case/ (one .toml per use case)
│ ├── template/
│ │ ├── base.jinja
│ │ └── use-case/ (one .jinja per use case)
│ ├── utils/ (OpenAI adapter, report generator)
│ ├── output/
│ └── main.py
│
├── validation/
│ ├── configurations/
│ │ ├── config.json (field types per use case)
│ │ └── boolean_semantics.toml (meaning of every boolean field)
│ ├── template/ (prompts of the LLM validator)
│ ├── utils/ (rule-based validator, LLM validator, Ollama client)
│ ├── reports/
│ ├── cleaned/
│ ├── main.py
│ └── clean.py
│
├── dataset-eval/
│ ├── notebooks/
│ ├── lib/
│ ├── figures/
│ ├── tables/
│ ├── requirements.txt
│ └── README.md
│
├── .env.example
├── requirements.txt
├── LICENSE
└── README.md
-
gt-generator/
Generates structured ground-truth JSON objects. -
json-to-mail-generator/
Converts ground-truth JSON objects into workplace emails. -
validation/
Validates whether the values of the ground truth are present and extractable in the generated emails (main.py) and writes the cleaned dataset (clean.py). -
dataset-eval/
Evaluates the dataset itself, not any model: difficulty composition, coverage and edge cases, label reliability, and realism against human email corpora. It has its ownREADME.mdandrequirements.txt.
LLMStructBench2 requires Python and the dependencies listed in requirements.txt. The code was developed with Python 3.11.
The pipeline uses two model backends:
- OpenAI API for generating ground-truth JSON objects and emails. An API key must be provided through an
.envfile. The model (gpt-5.4) is set ingt-generator/utils/openAI_api.pyandjson-to-mail-generator/utils/openAI_api.py. - Ollama for the LLM part of the validation, with the model
gemma4:31b. The host, the port, and the bearer token of the server are read from the.envfile. Without them the validator uses a local Ollama server athttp://localhost:11434and sends no authorization header.
Create and activate a virtual environment:
python3 -m venv .venv
source .venv/bin/activateInstall the required dependencies:
pip install -r requirements.txtCreate a .env file in the project root directory, for example by copying .env.example, and enter your values:
OPENAI_API_KEY=your_api_key_here
RUN_NAME=D5
OLLAMA_API_HOST=http://localhost
OLLAMA_API_PORT=11434
OLLAMA_API_KEY=OPENAI_API_KEYis the key for ground-truth and email generation.RUN_NAMEselects the dataset that all pipeline stages and the evaluation notebooks process.OLLAMA_API_HOSTandOLLAMA_API_PORTare the address of the Ollama server used by the validation.OLLAMA_API_KEYis the bearer token of that server. Leave it empty for a server without authentication.
The .env file is ignored by git, so keys and tokens stay out of the repository.
openaifor API-based generationjinja2for prompt templatingpyyamlandtomlifor configuration files (tomliis only needed below Python 3.11)python-dotenvfor loading environment variablesrequestsandftfyfor the Ollama client of the validation
The dataset quality evaluation has additional, heavier dependencies, which are listed in dataset-eval/requirements.txt.
All pipeline stages work on one run name, which keeps ground truth, generated emails, and validation reports aligned. The run name is set in a single place, as RUN_NAME in the .env file of the project root:
RUN_NAME=D5Example run names:
D3
D5
D4.test
meeting_fix_test
invoice_prompt_test
The released dataset is the run D5. Every stage stops with an error when RUN_NAME is not set. An environment variable of the same name takes precedence over the .env file, which is useful for a single call:
RUN_NAME=D4.test python3 main.pycd gt-generator
python3 main.pyThe use cases to generate are the entries of the scenarios list in gt-generator/main.py, and the number of objects requested per use case is number_of_jsons in configurations/general.yaml.
The generated files are written to:
gt-generator/output/<use_case>/<run_name>/
Example:
gt-generator/output/employee_sickleave_request/D5/
├── _full.json
├── split_1.json
├── split_2.json
└── ...
_full.jsoncontains the complete generated dataset for a use case together with the configuration it was generated with.split_*.jsoncontains chunks of at most five objects, used as input for email generation.
Run the email generator from the json-to-mail-generator directory:
cd ../json-to-mail-generator
python3 main.pyThe generator processes every use case that has the run under gt-generator/output/ and every email configuration in config/general.json. A run name passed as an argument overrides RUN_NAME for that call:
python3 main.py D4.testThe email generator reads from:
gt-generator/output/<use_case>/<run_name>/
and writes to:
json-to-mail-generator/output/<run_name>/<use_case>/
Example:
json-to-mail-generator/output/D5/employee_sickleave_request/
├── config_short_clean.json
├── config_short_clean_report.md
├── config_short_messy.json
├── config_short_messy_report.md
├── ...
├── config_long_messy.json
└── config_long_messy_report.md
config_*.jsoncontains the generated emails for a specific email configuration. Every case holds theemailTextand itsgroundTruth.config_*_report.mdcontains a readable report of that generation run.
There are ten email configurations, named config_<length>_<formatting>, with the lengths short, mid_short, mid, mid_long, and long and the formatting conditions clean and messy.
Run the validator from the validation directory:
cd ../validation
python3 main.pyvalidation/main.py sets the Ollama model (ollama_model) and the reference date BASE_DATE, which must match base_date in gt-generator/configurations/general.yaml.
The validator reads generated emails from:
json-to-mail-generator/output/<run_name>/
and writes to:
validation/reports/
Example:
validation/reports/
├── D5.md (readable validation report)
├── D5_failed_cases.json (cases with at least one rejected value, input of clean.py)
└── D5_decisions.json (every decision of the LLM validator with its reason)
The validation works in two steps. Rule-based matching first searches every value of the ground truth in the email, in all the forms the value may take in text. The values the rules cannot match, and all boolean values, are then judged by the LLM validator. A case fails when at least one of its values is rejected.
python3 clean.pyThe cleaner reads the failed cases of the validation run and writes a cleaned copy of the dataset to:
validation/cleaned/<run_name>/<use_case>/config_*.json
validation/cleaned/<run_name>/_clean_manifest.json
The constant MODE in validation/clean.py selects how failed cases are handled:
MODE = "remove"drops every failed case.MODE = "null"(default) sets a rejected value tonullin the ground truth when the email only omits a single nullable field, and drops the case otherwise.
The generated emails under json-to-mail-generator/output/ are never modified. The manifest lists every removed case and every nulled field. For the run D5, cleaning removed 46 of 6,100 emails and nulled 25 fields, which leaves the 6,054 emails of the released dataset.
The cleaned run is published as the Hugging Face dataset HTW-KI-Werkstatt/LlmStructBench2, with one JSONL file per scenario and the schema of one ground-truth object per scenario. The folder dataset/ is ignored by this repository because it is the local checkout of that Hugging Face repository.
The notebooks in dataset-eval/notebooks/ report on the cleaned dataset under validation/cleaned/<run_name>/. They use the same RUN_NAME as the pipeline. See dataset-eval/README.md for setup and usage.
LLMStructBench2 uses separate configuration files for ground-truth generation, email generation, and validation.
This separation makes it possible to change schemas, prompts, email styles, and validation rules independently.
Configured in:
gt-generator/configurations/
Important files and directories:
gt-generator/configurations/general.yaml
gt-generator/configurations/use-case/
gt-generator/schemas/
gt-generator/template/
general.yamlcontains global generation settings, such as the reference datebase_date, the number of objects per use case, and the probabilities for name diversity and missing names.use-case/*.tomlcontains scenario-specific generation rules, parameters, and prompt instructions.schemas/*.jsondefines the expected JSON structure for each use case.template/contains the Jinja templates used to construct prompts:base.jinjafor all use cases anduse-case/*.jinjafor the parameters of one use case.
Configured in:
json-to-mail-generator/config/
Important files and directories:
json-to-mail-generator/config/general.json
json-to-mail-generator/config/use-case/
json-to-mail-generator/template/
general.jsondefines the ten email configurations.use-case/*.tomlcontains use-case-specific email instructions.template/contains the Jinja templates used to construct email generation prompts:base.jinjafor all use cases anduse-case/*.jinjafor one use case.
Each email configuration sets the following parameters:
e_lengthfor the length tier (1 to 5)e_tonefor the tone (1 formal to 4 unprofessional)e_structurefor the formatting (1 well formatted to 3 very messy)p_noisefor the probability of noisep_signaturefor the probability of a signaturelanguageandoutput_format
The clean configurations use a formal tone, a well formatted structure, and no noise. The messy configurations use an unprofessional tone, a very messy structure, and noise. This allows the same ground-truth object to be rendered into different email styles while preserving the same structured information.
Configured in:
validation/configurations/
Important files and directories:
validation/configurations/config.json
validation/configurations/boolean_semantics.toml
validation/template/
config.jsonassigns a type to the fields of each use case (name,mail,date,time,price,number,count,currency,iban,enum,boolean). The type selects the matching rules. Fields without a type are matched as plain text.boolean_semantics.tomldescribes the meaning of every boolean field for the LLM validator.template/contains the prompts of the LLM validator.
The validator checks generated emails against the corresponding ground-truth data. Validation is scenario-specific because each use case has different fields, optional values, and logical dependencies. Before a run starts, the validator compares config.json with the schemas in gt-generator/schemas/ and aborts when they do not match.
Typical checks include:
- dates and times
- names and email addresses
- boolean values
- monetary amounts
- enum values
- nested arrays
- optional
nullfields
| Use Case | Description | Main Extraction Challenges |
|---|---|---|
employee_sickleave_request |
Employee absence notifications due to illness. | Nullable end date, partial-day absences with start and end time, boolean fields for doctor note and work from home. |
borrowed_item_reminder |
Reminders for returning borrowed company items. | Arrays of borrowed items, quantities, return dates, overdue flag, optional new return date and late fees. |
invoice_payment_request |
Vendor emails requesting invoice payment. | Invoice arrays with line items, monetary amounts, VAT information, payment methods, bank details, payment status, overdue and late-fee fields. |
meeting_reschedule |
Emails about cancelled, moved, or proposed meeting times. | Old and new dates and times, proposed time slots, attendee lists, virtual vs. physical meetings, meeting IDs, status and action enums. |
employee_summit_requests |
Employee requests to attend one or more professional summits. | Summit arrays, date ranges, travel requirements, participant counts, virtual attendance flags. |
shift_swap |
Requests for shift coverage or notifications that cover has been arranged. | Shift date and time range, cover person with nullable name and email, boolean cover status, employee role. |
visitor_access_notification |
Emails about visitor access to a company site or office. | Deeply nested objects, ID type and last digits, access date and time window, escort requirement, permitted areas with access mode. |
permissions_change |
Requests for and decisions about changed access permissions. | Enum-heavy fields (email type, reason, duration, decision), temporary vs. permanent access with nullable end date, arrays of affected systems with current and requested access level. |
The use cases test different aspects of structured information extraction, including nested JSON structures, arrays, nullable fields, indirect boolean expressions, date normalization, monetary values, and noisy email formatting.
To add a new use case, add the required schema, generation configuration, email instructions, and validation support. All files of one use case share the same name, which is also the name of its output folders.
Create a schema file:
gt-generator/schemas/<new_use_case>.json
The schema describes an object with a single requests array, whose items are the ground-truth objects. It should define required fields, nested objects, arrays, enum values, and nullable fields. The schema is sent to the OpenAI API as a strict structured-output schema, so it has to meet the requirements of that mode.
Create a use-case configuration and its parameter template:
gt-generator/configurations/use-case/<new_use_case>.toml
gt-generator/template/use-case/<new_use_case>.jinja
The configuration should define the scenario description, generation rules, value distributions, logical constraints, and domain-specific guidance. Then add the use case to the scenarios list in gt-generator/main.py.
Create the corresponding email generation configuration and template:
json-to-mail-generator/config/use-case/<new_use_case>.toml
json-to-mail-generator/template/use-case/<new_use_case>.jinja
The configuration should describe how ground-truth fields should be expressed in natural language emails, including required fields, optional fields, booleans, dates, times, amounts, and enum values.
Add the use case to:
validation/configurations/config.json
validation/configurations/boolean_semantics.toml
config.json needs an entry for the use case that assigns a type to its fields. A use case without an entry is skipped by the validator. Every boolean field should get a description in boolean_semantics.toml.
Add the use case to the SCENARIOS list in dataset-eval/lib/constants.py.
gt-generator/schemas/<new_use_case>.json
gt-generator/configurations/use-case/<new_use_case>.toml
gt-generator/template/use-case/<new_use_case>.jinja
gt-generator/main.py (scenarios list)
json-to-mail-generator/config/use-case/<new_use_case>.toml
json-to-mail-generator/template/use-case/<new_use_case>.jinja
validation/configurations/config.json
validation/configurations/boolean_semantics.toml
dataset-eval/lib/constants.py (SCENARIOS list)
After adding the use case, run the full pipeline and inspect both the generated emails and the validation report.
Whenever possible, make changes in use-case-specific configuration files instead of shared base logic.
Use-case-specific files are located in:
gt-generator/configurations/use-case/
gt-generator/template/use-case/
json-to-mail-generator/config/use-case/
json-to-mail-generator/template/use-case/
This keeps changes isolated and reduces the risk of breaking other scenarios.
Shared base templates are used across multiple use cases. Changes to base templates can affect all scenarios at once, so they should only be changed when the behavior is intended to apply globally.
Generated emails should preserve all information required by the corresponding ground-truth object.
When changing prompts or templates, check that:
- required fields are still mentioned
- numeric values remain extractable
- dates and times are not lost
- enum values are expressed clearly enough
- boolean values are not ambiguous
- optional fields are handled consistently
- company names, IDs, and email addresses are not altered
Use a new run name when testing changes to prompts, schemas, or validation rules, by changing RUN_NAME in the .env file.
Examples:
D3_meeting_fix
invoice_prompt_test
borrowed_items_validation_check
Every stage writes to the folder of its run name and overwrites existing files there. A new run name prevents older outputs from being overwritten and makes it easier to compare results between runs.
LLMStructBench2 is experimental and still under active development.
- The use cases of the ground-truth generator are selected in the
scenarioslist ingt-generator/main.py. - The models are set in the code, not in a configuration file.
- Validation rules are scenario-specific and must be added explicitly for new use cases.
- Boolean values and all values the rules cannot match are judged by an LLM, which can introduce non-deterministic results.
- Small prompt or template changes can affect multiple generated fields.
- Generated emails are synthetic and should not be treated as a replacement for real-world email corpora.
- Add CLI options for selecting specific use cases.
- Add CLI options for selecting specific email configurations.
- Improve validation reports with more detailed error grouping.
- Add automated comparison between different runs.
- Add example datasets for quick testing.
If generation fails because no API key is available, check that a .env file exists in the project root directory:
OPENAI_API_KEY=your_api_key_hereAlso make sure that the virtual environment is activated and that python-dotenv is installed.
Check that the run name matches the ground-truth output directory.
For example:
RUN_NAME=D5expects ground-truth files under:
gt-generator/output/<use_case>/D5/
If the folder does not exist, run the ground-truth generator first or use the correct run name. Use cases without this run are skipped.
All stages read the run name from RUN_NAME in the .env file of the project root. If a stage processes another run than expected, check whether a RUN_NAME environment variable is set in your shell, because it takes precedence over the .env file, and whether a run name was passed to the email generator as an argument.
The LLM validator sends its requests to the Ollama server configured in the .env file. If the requests fail, check OLLAMA_API_HOST, OLLAMA_API_PORT, and OLLAMA_API_KEY there, and that the model named in validation/main.py is available on the server. A value whose LLM call failed is reported as inconclusive and treated as rejected.
If validation reports many missing fields, inspect the generated emails manually.
Possible causes include:
- the email prompt does not require the field explicitly enough
- the field is expressed too indirectly
- the value was changed during email generation
- the validator is too strict
- the schema contains a field that is difficult to express naturally
The first place to check is usually:
json-to-mail-generator/config/use-case/
If generated JSON objects contain logical errors, check the corresponding ground-truth use-case configuration:
gt-generator/configurations/use-case/
Typical issues include overdue flags that do not match dates, nullable fields being filled incorrectly, boolean contradictions, invalid date ranges, or inconsistent payment and fee fields.
If a change unexpectedly affects multiple scenarios, check whether a shared base template or global configuration was modified.
Use-case-specific changes should usually be made in:
gt-generator/configurations/use-case/
json-to-mail-generator/config/use-case/
The code in this repository is released under the MIT license, see LICENSE. The dataset is released under the Creative Commons Attribution 4.0 International license (CC BY 4.0), see the dataset repository.