Skip to content

inspect_evals_utils.readmes.sections

Generic script to add missing section tags to eval READMEs.

This script scans all eval READMEs and adds HTML comment tags for auto-generated sections if they don't already exist. It can intelligently place the new section after a specified list of existing sections (in priority order).

Usage

inspect-evals-readmes add-section --key Parameters --insert-after Options --insert-after Usage

The script will: 1. Discover all eval paths from individual eval.yaml files 2. Check each README to see if the section tags already exist 3. If not, insert the tags after the first found section from --insert-after list 4. If none of those sections exist, append to the end of the file

Note: ": Automatically Generated" is automatically appended to all keys.

Adapted from: https://github.com/UKGovernmentBEIS/inspect_evals/blob/main/tools/add_readme_section.py

normalize_key

normalize_key(key: str) -> str

Normalize a key by ensuring it ends with ': Automatically Generated'.

Parameters:

Name Type Description Default
key str

The base key (e.g., "Parameters" or "Parameters: Automatically Generated")

required

Returns:

Type Description
str

Normalized key with the suffix

has_section_tags

has_section_tags(readme_path: Path, key: str) -> bool

Check if a README already has the specified section tags.

Parameters:

Name Type Description Default
readme_path Path

Path to the README file

required
key str

The section key (will be normalized)

required

Returns:

Type Description
bool

True if the section tags exist, False otherwise

find_insertion_point

find_insertion_point(
    lines: list[str], insert_after_keys: list[str]
) -> int | None

Find the line index where the new section should be inserted.

For each key (in priority order), tries two strategies: 1. Look for HTML comment tag (e.g., ) 2. Look for markdown header (e.g., ## Options)

Parameters:

Name Type Description Default
lines list[str]

List of lines from the README

required
insert_after_keys list[str]

List of section keys to try inserting after (in priority order)

required

Returns:

Type Description
int | None

Line index to insert after, or None if no matching section found

add_section_tags

add_section_tags(
    readme_path: Path,
    key: str,
    insert_after_keys: list[str],
) -> bool

Add section tags to a README if they don't already exist.

Parameters:

Name Type Description Default
readme_path Path

Path to the README file

required
key str

The section key to add (will be normalized)

required
insert_after_keys list[str]

List of section keys to try inserting after (in priority order)

required

Returns:

Type Description
bool

True if tags were added, False if they already existed or README doesn't exist

add_section

add_section(
    src_dir: Path, key: str, insert_after: list[str]
) -> list[Path]

Add the tags for key to every eval README under src_dir that lacks them.

Parameters:

Name Type Description Default
src_dir Path

Directory holding <eval>/eval.yaml packages.

required
key str

Section key, e.g. "Parameters"; ": Automatically Generated" is appended.

required
insert_after list[str]

Section keys to insert after, in priority order. If none is found, the tags are appended to the end of the file.

required

Returns:

Type Description
list[Path]

The README paths that gained the tags.