Implementation:Openai Evals Postprocessors
| Knowledge Sources | |
|---|---|
| Domains | Evaluation, Text Processing |
| Last Updated | 2026-02-14 10:00 GMT |
Overview
Concrete text-cleaning utilities for post-processing solver output provided by the evals library.
Description
The postprocessors module defines three lightweight PostProcessor subclasses that normalise the text returned by any Solver before it is compared against expected answers.
- Strip -- removes leading and trailing whitespace (including newlines) from the solver output by calling Python's built-in
str.strip(). - RemoveQuotes -- strips a matching pair of surrounding quotation marks (single or double). The quotes must appear as the very first and very last characters; unmatched or interior quotes are left untouched. If the output is shorter than two characters, no transformation is applied.
- RemovePeriod -- removes any trailing period(s) from the output using
str.rstrip(".").
Each class implements the __call__ protocol, accepting a SolverResult and returning a new or mutated SolverResult with the cleaned output string.
Usage
These postprocessors are typically referenced by their fully-qualified class names inside solver YAML configurations (e.g. under the postprocessors key). They can also be imported directly for use in custom solver pipelines or unit tests where deterministic output normalisation is needed.
Code Reference
Source Location
- Repository: Openai_Evals
- File: evals/solvers/postprocessors/postprocessors.py
- Lines: 1-43
Signature
class Strip(PostProcessor):
def __call__(self, result: SolverResult) -> SolverResult:
"""Strip leading and trailing whitespace from the output, including newlines."""
class RemoveQuotes(PostProcessor):
def __call__(self, result: SolverResult) -> SolverResult:
"""Remove matching pair of quotes (single or double) from beginning and end of output."""
class RemovePeriod(PostProcessor):
def __call__(self, result: SolverResult) -> SolverResult:
"""Remove trailing period(s) from the output."""
Import
from evals.solvers.postprocessors.postprocessors import Strip, RemoveQuotes, RemovePeriod
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| result | SolverResult |
Yes | The solver result whose output string will be cleaned. Passed as the sole positional argument when the postprocessor is called.
|
Outputs
| Name | Type | Description |
|---|---|---|
| result | SolverResult |
A SolverResult with the transformed output string. Strip returns a brand-new SolverResult (preserving metadata); RemoveQuotes and RemovePeriod mutate the _output attribute of the original object and return it.
|
Usage Examples
from evals.solvers.solver import SolverResult
from evals.solvers.postprocessors.postprocessors import Strip, RemoveQuotes, RemovePeriod
# Create a raw solver result with messy output
raw = SolverResult(' "Hello world." ')
# 1. Strip whitespace
strip = Strip()
result = strip(raw)
# result.output == '"Hello world."'
# 2. Remove surrounding quotes
remove_quotes = RemoveQuotes()
result = remove_quotes(result)
# result.output == 'Hello world.'
# 3. Remove trailing period
remove_period = RemovePeriod()
result = remove_period(result)
# result.output == 'Hello world'
# Chaining postprocessors in sequence
pipeline = [Strip(), RemoveQuotes(), RemovePeriod()]
result = SolverResult(' "Answer." ')
for pp in pipeline:
result = pp(result)
# result.output == 'Answer'