Skip to content

Call preprocess() with a raw email string, then pass the result to toLLMContext() to get clean Markdown output.

import { preprocess, toLLMContext } from "langmail"
import { readFileSync } from "fs"
// load a raw .eml file
const raw = readFileSync("email.eml", "utf8")
// parse and clean
const parsed = await preprocess(raw)
// serialize to LLM-ready Markdown
const context = toLLMContext(parsed)
console.log(context)

Given a typical reply-chain email, the output looks like this:

From: Alice <alice@example.com>
Subject: Q4 budget review
Date: 2024-11-12
Hi,
Following up on the Q4 numbers. Can you send
the updated forecast by Friday?
— [quoted reply removed] —
— [signature removed] —
from langmail import preprocess, to_llm_context
with open("email.eml") as f:
raw = f.read()
parsed = preprocess(raw)
context = to_llm_context(parsed)
print(context)
use langmail_core::{ preprocess, to_llm_context };
let raw = std::fs::read_to_string("email.eml")?;
let parsed = preprocess(&raw)?;
let context = to_llm_context(&parsed);
println!("{}", context);