> 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 full documentation content, see https://docs.nvidia.com/nemo/gym/llms-full.txt.

# nemo_gym.prompt

Prompt configuration: YAML-based prompt templates applied at rollout time.

Prompt templates are mutually exclusive with pre-populated
`responses_create_params.input` values. This separation enables prompt
sweeps without re-preparing data.

## Module Contents

### Classes

| Name                                                                    | Description                                                              |
| ----------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| [`MaterializePromptsConfig`](#nemo_gym-prompt-MaterializePromptsConfig) | Apply a prompt template to raw JSONL data, producing materialized JSONL  |
| [`PromptConfig`](#nemo_gym-prompt-PromptConfig)                         | Schema for a prompt YAML file. `user` is required, `system` is optional. |

### Functions

| Name                                                                              | Description                                                                                                 |
| --------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| [`_resolve_path`](#nemo_gym-prompt-_resolve_path)                                 | Resolve a path relative to the Gym root (PARENT\_DIR), consistent with config\_paths resolution.            |
| [`apply_prompt_to_row`](#nemo_gym-prompt-apply_prompt_to_row)                     | Apply prompt\_config to a row, building responses\_create\_params.input.                                    |
| [`fill_prompt`](#nemo_gym-prompt-fill_prompt)                                     | Apply a prompt template to a data row, producing message dicts.                                             |
| [`load_prompt_config`](#nemo_gym-prompt-load_prompt_config)                       | Load and validate a YAML prompt config file.                                                                |
| [`materialize_prompts`](#nemo_gym-prompt-materialize_prompts)                     | Apply a prompt template to raw JSONL data, producing materialized JSONL.                                    |
| [`materialize_prompts_cli`](#nemo_gym-prompt-materialize_prompts_cli)             | CLI entry point for ng\_materialize\_prompts.                                                               |
| [`validate_prompt_compatibility`](#nemo_gym-prompt-validate_prompt_compatibility) | Validate that no rows have pre-populated responses\_create\_params.input when a prompt\_config is provided. |

### API

<Anchor id="nemo_gym-prompt-MaterializePromptsConfig">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    class nemo_gym.prompt.MaterializePromptsConfig()
    ```
  </CodeBlock>
</Anchor>

<Indent>
  **Bases:** [BaseNeMoGymCLIConfig](/nemo-gym/nemo_gym/config_types#nemo_gym-config_types-BaseNeMoGymCLIConfig)

  Apply a prompt template to raw JSONL data, producing materialized JSONL
  with populated `responses_create_params.input` for RL training.

  Examples:

  <CodeBlock showLineNumbers={false}>
    ```python
    ng_materialize_prompts \
        +input_jsonl_fpath=data/my_dataset.jsonl \
        +prompt_config=/path/to/my_prompt.yaml \
        +output_jsonl_fpath=my_dataset_materialized.jsonl
    ```
  </CodeBlock>

  <ParamField path="input_jsonl_fpath" type="str" />

  <ParamField path="output_jsonl_fpath" type="str" />

  <ParamField path="prompt_config" type="str" />
</Indent>

<Anchor id="nemo_gym-prompt-PromptConfig">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    class nemo_gym.prompt.PromptConfig()
    ```
  </CodeBlock>
</Anchor>

<Indent>
  **Bases:** `BaseModel`

  Schema for a prompt YAML file. `user` is required, `system` is optional.

  <ParamField path="system" type="Optional[str] = None" />

  <ParamField path="user" type="str" />
</Indent>

<Anchor id="nemo_gym-prompt-_resolve_path">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_gym.prompt._resolve_path(
        path: str
    ) -> pathlib.Path
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Resolve a path relative to the Gym root (PARENT\_DIR), consistent with config\_paths resolution.
</Indent>

<Anchor id="nemo_gym-prompt-apply_prompt_to_row">
  <CodeBlock links={{"nemo_gym.prompt.PromptConfig":"#nemo_gym-prompt-PromptConfig"}} showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_gym.prompt.apply_prompt_to_row(
        row: dict,
        prompt_config: nemo_gym.prompt.PromptConfig
    ) -> dict
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Apply prompt\_config to a row, building responses\_create\_params.input.

  Other fields in responses\_create\_params (tools, metadata, temperature,
  max\_output\_tokens) are preserved. Returns a new dict (does not mutate the original).
</Indent>

<Anchor id="nemo_gym-prompt-fill_prompt">
  <CodeBlock links={{"nemo_gym.prompt.PromptConfig":"#nemo_gym-prompt-PromptConfig"}} showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_gym.prompt.fill_prompt(
        prompt_config: nemo_gym.prompt.PromptConfig,
        row: dict
    ) -> typing.List[typing.Dict[str, str]]
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Apply a prompt template to a data row, producing message dicts.

  Placeholders (`&#123;field_name&#125;`) are filled from the row's top-level
  fields. Literal braces must be doubled (`&#123;&#123;` / `&#125;&#125;`).
</Indent>

<Anchor id="nemo_gym-prompt-load_prompt_config">
  <CodeBlock links={{"nemo_gym.prompt.PromptConfig":"#nemo_gym-prompt-PromptConfig"}} showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_gym.prompt.load_prompt_config(
        path: str
    ) -> nemo_gym.prompt.PromptConfig
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Load and validate a YAML prompt config file.

  Relative paths are resolved against the Gym root directory (`PARENT_DIR`),
  consistent with how `config_paths` and other Gym paths are resolved.

  Returns a `PromptConfig` with required `user` and optional `system` fields.
  Each value is a string template with `&#123;placeholder&#125;` syntax.
  Results are cached so the same file is only parsed once.
</Indent>

<Anchor id="nemo_gym-prompt-materialize_prompts">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_gym.prompt.materialize_prompts(
        input_jsonl: str,
        prompt_config: str,
        output_jsonl: str
    ) -> None
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Apply a prompt template to raw JSONL data, producing materialized JSONL.

  Reads each row from `input_jsonl`, validates that no row has pre-populated
  `responses_create_params.input`, applies the prompt template, and writes
  the result to `output_jsonl`.

  **Parameters:**

  <ParamField path="input_jsonl" type="str">
    Path to raw JSONL (no responses\_create\_params.input).
  </ParamField>

  <ParamField path="prompt_config" type="str">
    Path to prompt YAML file.
  </ParamField>

  <ParamField path="output_jsonl" type="str">
    Path to write materialized JSONL (with responses\_create\_params.input).
  </ParamField>
</Indent>

<Anchor id="nemo_gym-prompt-materialize_prompts_cli">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_gym.prompt.materialize_prompts_cli() -> None
    ```
  </CodeBlock>
</Anchor>

<Indent>
  CLI entry point for ng\_materialize\_prompts.
</Indent>

<Anchor id="nemo_gym-prompt-validate_prompt_compatibility">
  <CodeBlock links={{"nemo_gym.prompt.PromptConfig":"#nemo_gym-prompt-PromptConfig"}} showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_gym.prompt.validate_prompt_compatibility(
        rows: typing.List[dict],
        prompt_config: nemo_gym.prompt.PromptConfig
    ) -> None
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Validate that no rows have pre-populated responses\_create\_params.input when a prompt\_config is provided.

  Collects all violating row indices and reports them in a single error.
</Indent>