Skip to main content

formal-lib

CI

A Python library that provides structured representations of software verifier output.

Installation

Backends

The following backends are supported:

  • ESBMC
  • CBMC
  • Clang
  • PyTest
  • Kani

Frontend

pf (Pretty Format) is a CLI frontend for formal-lib. It can be invoked from the CLI to get formatted output from any supported backends. There are two ways to invoke pf; detailed below.

Using the -- Separator (Recommeded)

The verifier command is specified after the -- separator. Any builtin backend can be specified. For example:

pf -- esbmc --k-induction --k-step 2 --max-k-step 10 file.c

This makes it easier for some backends that use stderr like ESBMC as you don't need to redirect stderr to stdout before piping.

Pipe

Pipe verifier output to pf to parse it into structured output:

esbmc --k-induction --k-step 2 --max-k-step 10 file.c 2>&1 | pf

Piping as a method of invocation cannot measure the duration of execution, so that detail will be omitted from the output.

Library Examples

The following section shows some simple examples of the capability of formal-lib.

Running a Verifier

from pathlib import Path
from formal_lib import VerifierRunner

verifier = VerifierRunner(base_cmd=Path("/usr/bin/esbmc"), default_timeout=120)
result = verifier.verify_source(Path("main.c"))

for issue in result.issues:
    print(f"[{issue.severity}] {issue.error_type}: {issue.message}")

Analyzing Verifier Output

from formal_lib import detect_spec, IssueSpecOutputParser

output = open("verifier.log").read()
spec = detect_spec(output)
parser = IssueSpecOutputParser(spec)
result = parser.parse_output(output=output)

# Drop traces from system headers or other files not in your project
project_files = {Path("main.c"), Path("lib/utils.c")}
result = result.filter_traces(project_files)

for issue in result.issues:
    print(f"[{issue.severity}] {issue.error_type}: {issue.message}")

Passing ESBMC output to LiteLLM

from pathlib import Path
import litellm
from formal_lib import VerifierRunner
from formal_lib.specs import esbmc_spec
from formal_lib.issue import VerifierIssue

verifier = VerifierRunner(base_cmd=Path("/usr/bin/esbmc"), regex_spec=esbmc_spec)
result = verifier.verify_source(Path("main.c"))

if not result.successful:
    issue = result.primary_issue
    counterexample = ""
    if isinstance(issue, VerifierIssue):
        counterexample = f"\nCounterexample:\n{issue.counterexample_formatted}"

    source = Path("main.c").read_text()

    response = litellm.completion(
        model="gpt-4o",
        messages=[
            {
                "role": "user",
                "content": (
                    f"Fix the following {issue.error_type} in {issue.file_path}:{issue.line_number}:\n"
                    f"{issue.message}\n\n"
                    f"Stack trace:\n{issue.stack_trace_formatted}"
                    f"{counterexample}\n\n"
                    f"Source:\n```c\n{source}\n```"
                ),
            }
        ],
    )
    print(response.choices[0].message.content)

Cite

If you use formal-lib in your work, please cite it using the following BibTeX entry:

@misc{charalambous2026formallib,
  author       = {Charalambous, Yiannis},
  title        = {formal-lib: A shared interface for software verifier output},
  year         = {2026},
  howpublished = {\url{https://github.com/ByteRepair/formal-lib}},
}

Please cite the version you used; see the Releases page.

License

Copyright © 2026 The University of Manchester. Authored by Yiannis Charalambous.

[!NOTE] This project is offered under a dual-licence model: the open-source GNU AGPL-3.0, or a separate commercial licence for proprietary use.

For a commercial licence, contact UOM Innovation Factory (the commercialisation subsidiary of The University of Manchester) at contact@uominnovationfactory.com.

Download files

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

Source Distribution

formal_lib-1.1.0.tar.gz (102.2 kB view details)

Uploaded Source

Built Distribution

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

formal_lib-1.1.0-py3-none-any.whl (42.5 kB view details)

Uploaded Python 3

File details

Details for the file formal_lib-1.1.0.tar.gz.

File metadata

  • Download URL: formal_lib-1.1.0.tar.gz
  • Upload date:
  • Size: 102.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for formal_lib-1.1.0.tar.gz
Algorithm Hash digest
SHA256 5276789b4fdb6f420c496cdfc63c03ae03be2a2b4fa3aec15bccbf7b36bad229
MD5 ffcc17256e47ff70111bd2dcc042ce02
BLAKE2b-256 35e0283c8051d5c86e8d88c702d28acbdaa14bfc085a76abd4eb93dabea6be9d

See more details on using hashes here.

Provenance

The following attestation bundles were made for formal_lib-1.1.0.tar.gz:

Publisher: release.yml on ByteRepair/formal-lib

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

File details

Details for the file formal_lib-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: formal_lib-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 42.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for formal_lib-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c28290097033172f5cbe72ecf7466b1e07b33055c0e8fb3f9d6f27e0384db89
MD5 d98d691d7d6fdc54156ebe94145a93f9
BLAKE2b-256 c57375c983063aa2ef7ef9a0007332cd4894720d057e844143e14e0fff2de9ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for formal_lib-1.1.0-py3-none-any.whl:

Publisher: release.yml on ByteRepair/formal-lib

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

Release history Release notifications | RSS feed

1.2.0

2 files

This release

1.1.0 This release

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page