Implementation:Openai Evals HHHSolver
| Knowledge Sources | |
|---|---|
| Domains | Evaluation, Solvers |
| Last Updated | 2026-02-14 10:00 GMT |
Overview
Concrete tool for wrapping solvers with Helpful, Harmless, and Honest alignment prompts provided by the evals library.
Description
HHHSolver is a subclass of NestedSolver that prepends Helpful, Harmless, and Honest (HHH) example dialogues from Bai et al. (2022) to the prompt history before delegating to an inner solver. This is especially useful for completion models that are not instruction-tuned or chat-tuned, as the HHH context encourages the model to generate responses consistent with a well-aligned chatbot assistant.
During _solve, the solver restructures the TaskState as follows: the first HHH message becomes the new task_description (which sets the framing as "Below are a series of dialogues..."), the remaining HHH messages are prepended to the message history, and the original task description is inserted as a system message between the HHH examples and the actual conversation messages. This places the evaluation task within the context of an aligned assistant dialogue.
The name property returns the inner solver's name with an "_hhh" suffix, making it easy to identify HHH-wrapped solvers in logs and results.
Usage
Import HHHSolver when evaluating completion models (e.g., base GPT models) that lack instruction tuning. The HHH wrapper provides in-context alignment examples that help steer the model toward producing helpful, harmless, and honest outputs without requiring fine-tuning.
Code Reference
Source Location
- Repository: Openai_Evals
- File: evals/solvers/nested/hhh_solver.py
- Lines: 1-47
Signature
class HHHSolver(NestedSolver):
def __init__(
self,
solver: SolverSpec,
postprocessors: list[str] = [],
registry: Any = None,
):
...
@property
def solver(self) -> Solver:
...
def _solve(self, task_state: TaskState, **kwargs) -> SolverResult:
...
@property
def name(self) -> str:
# returns "{solver.name}_hhh"
...
Import
from evals.solvers.nested.hhh_solver import HHHSolver
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| solver | SolverSpec | Yes | Specification for the inner solver to wrap with HHH alignment context. |
| postprocessors | list[str] | No | List of postprocessor names to apply to solver output. Defaults to an empty list. |
| registry | Any | No | Registry object for resource lookup. |
| task_state | TaskState | Yes | The current evaluation task state, passed to _solve. Its task_description and messages are restructured with HHH context before delegation. |
Outputs
| Name | Type | Description |
|---|---|---|
| SolverResult | SolverResult | The result from the inner solver after processing the HHH-augmented prompt. |
| name | str | Returns "{solver.name}_hhh" to identify the HHH-wrapped solver. |
Usage Examples
from evals.solvers.nested.hhh_solver import HHHSolver
from evals.solvers.solver import SolverSpec
# Define HHHSolver via YAML-style config (typical usage)
# solver:
# class: evals.solvers.nested.hhh_solver:HHHSolver
# args:
# solver:
# class: evals.solvers.openai_solver:OpenAISolver
# args:
# model: davinci-002
# Programmatic usage - wrap a completion model with HHH context
inner_spec = SolverSpec(
class_name="evals.solvers.openai_solver:OpenAISolver",
args={"model": "davinci-002"},
)
solver = HHHSolver(solver=inner_spec)
result = solver(task_state)
print(result.output) # response guided by HHH alignment examples
print(solver.name) # e.g. "OpenAISolver_hhh"