Skip to content

Repository files navigation

lx-report-parser

Python report parser with a PyO3 Rust helper backend. The Python layer forwards normalized report text to a configurable LLM API and validates the response with Pydantic models that mirror the concepts in lx-data-models/STANDARD.md.

Python usage

from report_parser import LLMConfig, ReportParser

parser = ReportParser(
    LLMConfig(
        provider="openai-compatible",
        base_url="https://api.example.test",
        model="your-model",
        api_key="...",
    )
)

result = parser.parse("Gastroscopy performed. Polyp removed from antrum.")
print(result.summary.narrative)
print(result.model_dump_json(indent=2))

To return only a table row with the report name and summarized contents:

row = parser.parse_summary_table_row(
    "Gastroscopy performed. Polyp removed from antrum.",
    report_name="gastroscopy.txt",
)
print(row.model_dump())
# {"report_name": "gastroscopy.txt", "summarized_contents": "..."}

The CLI exposes the same compact shape:

report-parser ./report.txt --table

To classify each row of a legacy .xls workbook through the remote Ollama generate API and write a returned workbook with an added yes/no column:

report-parser ~/Desktop/Name.xls \
  --raw-prompt \
  --transport ssh-curl \
  --ssh-host gs-02 \
  --base-url http://172.16.255.22:11434 \
  --endpoint-path /api/generate \
  --model gemma4:e2b \
  --skip-header \
  --result-column-header lesion

The default output path is ~/Desktop/Name_With_Results.xls. Use --xls-column A or --xls-column 1 if only one workbook column contains the report text; otherwise each row is joined into the prompt.

Environment based configuration is available through:

  • REPORT_PARSER_LLM_PROVIDER
  • REPORT_PARSER_LLM_TRANSPORT
  • REPORT_PARSER_LLM_SSH_HOST
  • REPORT_PARSER_LLM_BASE_URL
  • REPORT_PARSER_LLM_MODEL
  • REPORT_PARSER_LLM_API_KEY
  • REPORT_PARSER_LLM_ENDPOINT_PATH

The default provider shape is Ollama-compatible because the referenced Nix environment already includes ollama, but both Ollama and OpenAI-compatible chat completion APIs are supported.

Rust backend

The Rust crate lives in rust/report_parser_rust_backend and exposes:

  • normalize_report_text
  • extract_report_sections
  • report_text_stats
  • build_report_prompt
  • extract_json_object

The Python package falls back to pure Python helpers if the extension has not been built yet.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages