Skip to main content

SafeLLM4SE

License Latest release PyPI

SafeLLM4SE is a Python toolkit for statistically principled evaluation of LLM-based software engineering systems. It treats each LLM execution as a sample from a stochastic process, then reports quality, stability, uncertainty, resource usage, and statistical comparisons instead of relying on a single run.

The project exposes three command-line programs:

  • safellm4se-sample: runs adaptive sampling with a user-selected evaluator.
  • safellm4se-report: summarizes one sampled task into a SafeLLM4SE report CSV.
  • safellm4se-compare: compares two sampled tasks with the SafeLLM4SE comparison protocol.

Install

SafeLLM4SE is available on PyPI as safellm4se, so you only need to run:

pip install "SafeLLM4SE[all]"

If you want to install SafeLLM4SE from its source code, check the installation details.

Quick Start

SafeLLM4SE collects repeated observations with safellm4se-sample. Then, it can be used to report or visualize one sample of observations with safellm4se-report, or compare task samples with safellm4se-compare.

Sampling

First, you need to generate a sample of repeated observations. For this purpose, safellm4se-sample loads an evaluator class and repeatedly calls it until a stopping condition is met (maximum number of tokens consumed or the confidence interval width is below a threshold). You commonly implement the process being measured as an evaluator, but we provide several example evaluators, including default implementations for Ollama, Gemini, and Groq APIs. The Gemini and Groq evaluators read GEMINI_API_KEY and GROQ_API_KEY from the process environment. If they are not set, SafeLLM4SE reads them from a .env file in the current working directory. The Ollama evaluators read the API host from OLLAMA_HOST in the same way.

For this example, we perform adaptive sampling on a random evaluator to generate two different samples:

safellm4se-sample --evaluator safellm4se.sampling.myevaluators.random_normal_evaluator --mean=60 --standard-deviation=20
safellm4se-sample --evaluator safellm4se.sampling.myevaluators.random_normal_evaluator --mean=40 --standard-deviation=10 

Reporting

If you have already created a sample of repeated observations with the task identifier task-id-1, stored in output/measurements.csv, you can create reports and visualizations with safellm4se-report. The report includes the sample size, token usage, central tendency, variability, and confidence interval information. The supported visualizations are boxplot, violin plot, empirical cumulative distribution function (ECDF), raincloud plot, and kernel density estimate (KDE).

Let's generate a report for two different task identifiers, task-id-1 and task-id-2, with boxplot and KDE visualizations:

safellm4se-report --input output/measurements.csv --output output/report-demo.csv --task-id task-id-1 --boxplot output/demo-boxplot.svg
safellm4se-report --input output/measurements.csv --output output/report-demo.csv --task-id task-id-2 --kde output/demo-kde.svg

Example CSV report generated with safellm4se-report for the LLMs qwen2.5-coder:7b and deepseek-coder:6.7b running HumanEval:

task_id model_name model_id N total_tokens theta_mean sd ci_method ci_low ci_high ci_width
task-id-54 qwen-coder qwen2.5-coder:7b 30 1,178,530 0.8272 0.0194 t 0.8200 0.8345 0.0145

Comparing

You can also compare two samples of repeated observations with safellm4se-compare. The report will tell you the estimated difference, confidence interval, statistical test, p-value, and effect size. It also generates figures comparing the two samples, including the visualizations mentioned in reporting.

Let's compare the two samples with task identifiers task-1 and task-1 using an independent test (adaptive sampling may generate different number of observations for each sample), and generate a raincloud plot:

safellm4se-compare --input output/measurements.csv --output output/comparing-demo.csv --task-id-1 task-id-1 --task-id-2 task-id-2 --test-type independent --raincloud output/comparing-demo-raincloud.svg

Example plot generated with safellm4se-compare for two different models (qwen2.5-coder:7b and deepseek-coder:6.7b) running HumanEval:

Two-sample raincloud plot

The following CSV comparison report has also been generated:

task_id_1 task_id_2 test_type estimated_difference ci_low ci_high statistical_test p_value effect_size_name effect_size effect_size_magnitude
task-id-54 task-id-56 independent 0.2083 0.1937 0.2224 Mann-Whitney U 2.86e-11 Cliff's delta 1.0 large

Documentation

License

See LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

safellm4se-0.1.1.3.tar.gz (78.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

safellm4se-0.1.1.3-py3-none-any.whl (95.5 kB view details)

Uploaded Python 3

File details

Details for the file safellm4se-0.1.1.3.tar.gz.

File metadata

  • Download URL: safellm4se-0.1.1.3.tar.gz
  • Upload date:
  • Size: 78.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for safellm4se-0.1.1.3.tar.gz
Algorithm Hash digest
SHA256 42be4e433ab419cc277eec76107792a4c3d327e31129c5cc391e1f0183d9de00
MD5 59f9bde9038961271fd3ee6878a09d00
BLAKE2b-256 df19005cf6643bbbeacd89f9e9b72f322cbc43eadd96b30083e951a2da7cc4d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for safellm4se-0.1.1.3.tar.gz:

Publisher: release.yml on francisco-ortin/SafeLLM4SE

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file safellm4se-0.1.1.3-py3-none-any.whl.

File metadata

  • Download URL: safellm4se-0.1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 95.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for safellm4se-0.1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6e4e3e8f1ce1d9c89790ce07bd6737fb8322c6e7ca64bfcc80234865f10cff15
MD5 0b7d1b6001e1d4526f9bbc5b92f9aa16
BLAKE2b-256 a9292d787054637def115c16c8ef9be48cdb1bc2587f095155a1bfb92ace0736

See more details on using hashes here.

Provenance

The following attestation bundles were made for safellm4se-0.1.1.3-py3-none-any.whl:

Publisher: release.yml on francisco-ortin/SafeLLM4SE

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.1.3 This release

2 files

0.1.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page