Skip to content

User templates

User templates define deterministic extraction for repeated issuer layouts. Their position among the readers depends on the domain and configured order; there is no universal priority rule for every booking type.

Use a template when an issuer’s layout is repeated and the current result needs correction, or when deterministic parsing is preferred. If existing parsing already works, a new template may add maintenance without improving it. Test both outbound and return legs, changed dates and missing optional fields.

Built-in templates are also a good baseline if you decide later you’d rather contribute your template upstream than keep it private — see Contributing.

Tools → Parser → Annotate. The menu entry is shown to admins only, but what you record is yours: every template is stored against the account that created it, and the API refuses another user’s template on every verb. (The instance-wide ones are the shipped built-ins, listed under Community Templates — those are a different thing, and only an admin refreshes them.)

  1. Provide a sample. Paste the body or upload an .eml/.msg file in the browser. The fuller and more representative, the better — pick a typical confirmation, not an edge case. Browser uploads preserve the sample headers the matcher needs; a lodging sample can be derived directly from that upload.
  2. Choose the domain. Flight, cruise, lodging or place. The annotation labels change to the fields that domain can describe. The current 2.7 workshop also derives templates for cruises, places and package tours; check the preview for the selected domain.
  3. Mark the detection signals.
    • Sender domain — pick from the auto-detected list, or type it.
    • Subject pattern — the parser auto-suggests a regex from the subject line of your sample; you can tighten it.
    • HTML fingerprint — a string that’s reliably present in the HTML body. Often the airline’s main domain name.
  4. Mark the field locations. The interactive editor highlights candidate fields and offers the labels for the selected domain: flight legs and airports; cruise ship, line, dates and ports; lodging name, stay dates, room, board and price; or place name, visit dates and location details.
  5. Save and test. The right side of the editor shows a live preview of the parser running against your sample; everything should highlight correctly. If a field isn’t picking up reliably, refine the rule (the editor lets you switch from text-match to regex).
  6. Verify against a second sample. Paste another email from the same airline (different flight, different date) into the test pane. The parser should pull all fields correctly.

Save. From now on, every email from that sender will parse through your template automatically.

How user templates rank in the parser pipeline

Section titled “How user templates rank in the parser pipeline”

The parser supports template-first and model-first ordering; template-first is the 2.7 default. A matching user template can override generic extraction, but a weak detection must allow other candidates to be tried. Do not assume a fixed eight-carrier fallback or guaranteed accuracy for an unfamiliar issuer. See Imports and parsers for the current chain.

Tools → Parser → My Templates lists every template you’ve recorded. For each:

  • View the matching rules and field-extraction patterns
  • Edit any rule — useful when the airline tweaks their email format
  • Delete to remove the template (the parser falls back to Ollama or whatever else applies)
  • Statistics — how many flights this template has parsed, average confidence score

Each saved template records its domain, sender/subject detection rules and domain-specific extraction rules. The preview runs those same rules before you save.

The reference example email is not stored by default — once the template’s rules are extracted, the example is discarded for privacy. If you’d rather keep the sample email for reference, the record-new screen has an opt-in toggle.

Templates aren’t shareable between TravStats instances out of the box — there’s no export/import yet for the ParserTemplate table. If you’ve recorded a useful template and want to contribute it upstream as a built-in:

  1. Fork github.com/Abrechen2/TravStats
  2. Add a JSON file to backend/src/services/parsers/templates/airlines/
  3. Update backend/src/services/parsers/templates/detector.ts with the detection signals
  4. Add a test fixture to backend/src/services/parsers/__tests__/
  5. PR

The detection rules in your private template translate directly to the built-in format. Most contributions are accepted within a release cycle.

User templates handle the common case (one airline, one sender domain, one fairly predictable email layout). They struggle with:

  • Codeshare confirmations where the operating carrier email is branded differently from the marketing carrier — fall back to Ollama, or let the flight-lookup API resolve the codeshare
  • Multi-airline emails (consolidator bookings with multiple legs operated by different carriers) — Ollama handles these better
  • Marketing emails that mention a flight number but aren’t a booking confirmation — usually filtered out by the subject regex, but if one slips through you’ll see it on the review screen and can delete it

Coverage depends on the installed templates and the documents you test. There is no guarantee for all European or non-European issuers. In 2.7 the template workshop also supports marking up examples for cruises, places and package tours; the common engine validates proposals before they are saved.