> This page is for version 0.7.0.
> For other versions, use one of these documentation indexes:
> - Main (default): https://docs.nvidia.com/nemo/gym/main/llms.txt
> - 0.7.0: https://docs.nvidia.com/nemo/gym/v0.7.0/llms.txt
> - 0.6.0: https://docs.nvidia.com/nemo/gym/v0.6.0/llms.txt
> - 0.5.1: https://docs.nvidia.com/nemo/gym/v0.5.1/llms.txt
> - 0.5.0: https://docs.nvidia.com/nemo/gym/v0.5.0/llms.txt
> - 0.4.0: https://docs.nvidia.com/nemo/gym/v0.4.0/llms.txt
> - 0.3.0: https://docs.nvidia.com/nemo/gym/v0.3.0/llms.txt
> - 0.2.1: https://docs.nvidia.com/nemo/gym/v0.2.1/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/gym/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/gym/_mcp/server.

# nemo_gym.verifiers.files

File checks for Python verifiers: the agent's workspace is a directory, these read it.

Standard library only (see `nemo_gym.verifiers`). Paths are relative to the workspace; a path that
escapes it (`..` or an absolute path outside it) reads as absent, so a task cannot be graded on files the
agent never owned.

## Module Contents

### Functions

| Name                                                                               | Description                                                                                     |
| ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| [`_resolve`](#nemo_gym-verifiers-files-_resolve)                                   | -                                                                                               |
| [`_without_trailing_newline`](#nemo_gym-verifiers-files-_without_trailing_newline) | -                                                                                               |
| [`file_exists`](#nemo_gym-verifiers-files-file_exists)                             | Whether `path` under the workspace is a regular file.                                           |
| [`read_text`](#nemo_gym-verifiers-files-read_text)                                 | The text of `path` under the workspace, or `None` when it is absent or not a file.              |
| [`text_file_equals`](#nemo_gym-verifiers-files-text_file_equals)                   | `1.0` when `path` under the workspace holds exactly `content` (one trailing newline tolerated). |

### API

```python
nemo_gym.verifiers.files._resolve(
    workspace: pathlib.Path | str,
    path: str | pathlib.Path
) -> pathlib.Path | None
```

```python
nemo_gym.verifiers.files._without_trailing_newline(
    text: str
) -> str
```

```python
nemo_gym.verifiers.files.file_exists(
    workspace: pathlib.Path | str,
    path: str | pathlib.Path
) -> bool
```

Whether `path` under the workspace is a regular file.

```python
nemo_gym.verifiers.files.read_text(
    workspace: pathlib.Path | str,
    path: str | pathlib.Path,
    encoding: str = 'utf-8',
    strip_trailing_newline: bool = True
) -> str | None
```

The text of `path` under the workspace, or `None` when it is absent or not a file.

One trailing newline is dropped by default (`echo` and most editors end a file with one, and a verifier
comparing `read_text(...) == "answer"` should not fail on it); pass `strip_trailing_newline=False` for the
bytes as written. Undecodable bytes are replaced rather than raised, so a verifier comparing text never
crashes on binary output.

```python
nemo_gym.verifiers.files.text_file_equals(
    workspace: pathlib.Path | str,
    path: str | pathlib.Path,
    content: str,
    strip_trailing_newline: bool = True
) -> float
```

`1.0` when `path` under the workspace holds exactly `content` (one trailing newline tolerated).

A complete verifier: `verify = functools.partial(text_file_equals, path="hello.txt", content="hello")`.