> 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.token_id_capture.fingerprint

Fingerprint conversation content across serving dialects.

These are pure functions over message lists.
They hold no state and read no store.
Any server may import them.
Lineage state stays confined to the capture locus and the finalizer.

`assistant_fingerprint` hashes only model-authored turns.
It identifies the call that produced the last model-authored turn.
`conversation_digest` hashes every turn, including tool results.
A parent resolver uses it to verify context before reusing tokens.

Chat, Responses, and Anthropic shapes normalize to the same hash input.
The hash layout is tagged and length-delimited.
No concatenation of fields can collide with another field boundary.

## Module Contents

### Functions

| Name                                                                                                | Description                                                          |
| --------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| [`_canonical_json`](#nemo_gym-token_id_capture-fingerprint-_canonical_json)                         | Serialize JSON-compatible prompt content without losing structure.   |
| [`_content_of`](#nemo_gym-token_id_capture-fingerprint-_content_of)                                 | Return typed content parts without discarding prompt-shaping blocks. |
| [`_is_assistant_authored`](#nemo_gym-token_id_capture-fingerprint-_is_assistant_authored)           | Return whether the model produced this item.                         |
| [`_tool_results_of`](#nemo_gym-token_id_capture-fingerprint-_tool_results_of)                       | Return tool result identities and payloads across dialects.          |
| [`_tools_of`](#nemo_gym-token_id_capture-fingerprint-_tools_of)                                     | Return tool calls as `(id, name, canonical arguments)` tuples.       |
| [`_update_field`](#nemo_gym-token_id_capture-fingerprint-_update_field)                             | Hash one tagged, length-delimited UTF-8 field.                       |
| [`assistant_fingerprint`](#nemo_gym-token_id_capture-fingerprint-assistant_fingerprint)             | Fingerprint the model-authored turns of a request, in order.         |
| [`canonicalize_tool_arguments`](#nemo_gym-token_id_capture-fingerprint-canonicalize_tool_arguments) | Normalize a tool call's arguments for comparison only.               |
| [`conversation_digest`](#nemo_gym-token_id_capture-fingerprint-conversation_digest)                 | Hash every turn of a conversation, model-authored or not.            |

### Data

[`FINGERPRINT_VERSION`](#nemo_gym-token_id_capture-fingerprint-FINGERPRINT_VERSION)

[`_CONTEXT_DOMAIN`](#nemo_gym-token_id_capture-fingerprint-_CONTEXT_DOMAIN)

[`_FINGERPRINT_DOMAIN`](#nemo_gym-token_id_capture-fingerprint-_FINGERPRINT_DOMAIN)

### API

```python
nemo_gym.token_id_capture.fingerprint._canonical_json(
    value: typing.Any
) -> str
```

Serialize JSON-compatible prompt content without losing structure.

```python
nemo_gym.token_id_capture.fingerprint._content_of(
    content: typing.Any
) -> list[tuple[str, str]]
```

Return typed content parts without discarding prompt-shaping blocks.

Tool calls are normalized separately by `_tools_of`.
Tool results are normalized separately by `_tool_results_of`.

```python
nemo_gym.token_id_capture.fingerprint._is_assistant_authored(
    message: dict
) -> bool
```

Return whether the model produced this item.

Chat and Anthropic use the `assistant` role.
Responses tool calls are roleless `function_call` items.

```python
nemo_gym.token_id_capture.fingerprint._tool_results_of(
    message: dict
) -> list[tuple[str, str]]
```

Return tool result identities and payloads across dialects.

Responses stores results in standalone `function_call_output` items.
Anthropic stores results in `tool_result` content blocks.
Chat stores results as plain message content.

```python
nemo_gym.token_id_capture.fingerprint._tools_of(
    message: dict
) -> list[tuple[str, str, str]]
```

Return tool calls as `(id, name, canonical arguments)` tuples.

Chat stores calls in the message's `tool_calls` field.
Anthropic stores calls in `tool_use` content blocks.
Responses stores each call as a standalone `function_call` item.

```python
nemo_gym.token_id_capture.fingerprint._update_field(
    hasher: typing.Any,
    tag: bytes,
    value: str
) -> None
```

Hash one tagged, length-delimited UTF-8 field.

```python
nemo_gym.token_id_capture.fingerprint.assistant_fingerprint(
    messages: list[dict]
) -> str
```

Fingerprint the model-authored turns of a request, in order.

The fingerprint identifies the call that produced the last model-authored turn.
User and tool content is excluded from the lookup key.
Dialect-specific tool-call shapes normalize to the same hash input.

```python
nemo_gym.token_id_capture.fingerprint.canonicalize_tool_arguments(
    value: typing.Any
) -> str
```

Normalize a tool call's arguments for comparison only.

Harnesses can reserialize tool-call arguments between turns.
Comparison uses sorted-key JSON with normalized separators.
The record retains the model's original string.

```python
nemo_gym.token_id_capture.fingerprint.conversation_digest(
    messages: list[dict]
) -> str
```

Hash every turn of a conversation, model-authored or not.

`assistant_fingerprint` ignores user and tool content.
This digest covers that omitted context.
A mismatch rejects the parent before its tokens are reused.

```python
nemo_gym.token_id_capture.fingerprint.FINGERPRINT_VERSION = 1
```

```python
nemo_gym.token_id_capture.fingerprint._CONTEXT_DOMAIN = b'nemo-gym-lineage-context'
```

```python
nemo_gym.token_id_capture.fingerprint._FINGERPRINT_DOMAIN = b'nemo-gym-lineage'
```