> ## Documentation Index
> Fetch the complete documentation index at: https://docs.corti.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Path 2 — `templateRef` with runtime overrides

> Reference a stored template and patch its instructions, section headings or output schemas for a single call — without mutating the underlying template.

<Badge className="accent-badge" shape="rounded">Beta</Badge>

← Back to [Guided Synthesis overview](/textgen/documents-guided-synthesis)

Use this when 90% of the base template is right but you want to patch a section title, swap a section's writing style, or replace its output schema — for a single call, without changing the underlying template.

A new **auto-generated template aggregate** is persisted with `inheritedFromId` pointing at the base template. The aggregate is fully resolved and drift-proof — but **retained for 30 days only** (see [Auto-generated template aggregates — 30-day retention](/textgen/documents-guided-synthesis#auto-generated-template-aggregates-30-day-retention)).

<CodeGroup>
  ```ts title="JavaScript" expandable theme={null}
  // Replace these with your values
  const INTERACTION_ID = "<your-interaction-id>";
  const SECTION_ID = "<your-section-id>";
  const TEMPLATE_ID = "<your-template-id>";

  const result = await client.documents.generate({
    outputLanguage: "en-US",
    interactionId: INTERACTION_ID,
    templateRef: {
      templateId: TEMPLATE_ID,
      overrides: {
        instructions: {
          prompt: "Produce a pediatric consultation note. Refer to the patient as the child.",
        },
        sections: [
          {
            sectionId: SECTION_ID,
            generation: {
              heading: "Anamnesis",
              instructions: {
                writingStylePrompt: "Family-centred language; use second person sparingly.",
              },
            },
          },
        ],
      },
    },
  });
  ```

  ```csharp title="C# .NET" expandable theme={null}
  using Corti;

  // Replace these with your values
  const string InteractionId = "<your-interaction-id>";
  const string SectionId = "<your-section-id>";
  const string TemplateId = "<your-template-id>";

  var result = await client.Documents.GenerateAsync(
      new GuidedDocumentsGenerateByTemplateRef
      {
          OutputLanguage = "en-US",
          InteractionId = InteractionId,
          TemplateRef = new GuidedTemplateRef
          {
              TemplateId = TemplateId,
              Overrides = new GuidedTemplateOverrides
              {
                  Instructions = new GuidedTemplateInstructions
                  {
                      Prompt = "Produce a pediatric consultation note. Refer to the patient as the child.",
                  },
                  Sections = new[]
                  {
                      new GuidedSectionOverride
                      {
                          SectionId = SectionId,
                          Generation = new GuidedSectionOverrides
                          {
                              Heading = "Anamnesis",
                              Instructions = new GuidedSectionInstructionsOverride
                              {
                                  WritingStylePrompt = "Family-centred language; use second person sparingly.",
                              },
                          },
                      },
                  },
              },
          },
      });
  ```

  ```python title="Python" expandable theme={null}
  import requests

  # Replace these with your values
  ENVIRONMENT = "<eu-or-us>"
  INTERACTION_ID = "<your-interaction-id>"
  SECTION_ID = "<your-section-id>"
  TEMPLATE_ID = "<your-template-id>"
  TENANT = "<your-tenant-name>"
  TOKEN = "<your-access-token>"

  response = requests.post(
      f"https://api.{ENVIRONMENT}.corti.app/v2/documents",
      headers={
          "Authorization": f"Bearer {TOKEN}",
          "Tenant-Name": TENANT,
          "Content-Type": "application/json",
      },
      json={
          "outputLanguage": "en-US",
          "interactionId": INTERACTION_ID,
          "templateRef": {
              "templateId": TEMPLATE_ID,
              "overrides": {
                  "instructions": {
                      "prompt": "Produce a pediatric consultation note. Refer to the patient as the child.",
                  },
                  "sections": [
                      {
                          "sectionId": SECTION_ID,
                          "generation": {
                              "heading": "Anamnesis",
                              "instructions": {
                                  "writingStylePrompt": "Family-centred language; use second person sparingly.",
                              },
                          },
                      },
                  ],
              },
          },
      },
  )
  response.raise_for_status()
  result = response.json()
  ```

  ```bash title="cURL" expandable theme={null}
  # Replace these with your values
  ENVIRONMENT="<eu-or-us>"
  INTERACTION_ID="<your-interaction-id>"
  SECTION_ID="<your-section-id>"
  TEMPLATE_ID="<your-template-id>"
  TENANT="<your-tenant-name>"
  TOKEN="<your-access-token>"

  curl --request POST \
    --url "https://api.${ENVIRONMENT}.corti.app/v2/documents" \
    --header "Authorization: Bearer ${TOKEN}" \
    --header "Tenant-Name: ${TENANT}" \
    --header "Content-Type: application/json" \
    --data "{
      \"outputLanguage\": \"en-US\",
      \"interactionId\": \"${INTERACTION_ID}\",
      \"templateRef\": {
        \"templateId\": \"${TEMPLATE_ID}\",
        \"overrides\": {
          \"instructions\": {
            \"prompt\": \"Produce a pediatric consultation note. Refer to the patient as the child.\"
          },
          \"sections\": [
            {
              \"sectionId\": \"${SECTION_ID}\",
              \"generation\": {
                \"heading\": \"Anamnesis\",
                \"instructions\": {
                  \"writingStylePrompt\": \"Family-centred language; use second person sparingly.\"
                }
              }
            }
          ]
        }
      }
    }"
  ```
</CodeGroup>

## Override semantics — important

The override patches obey **different merge rules per field**:

* `instructions` (template- or section-level) is **per-field partial**. Any field you omit is inherited from the parent's published version.
* `outputSchema` is **wholesale**. Whatever you submit fully replaces the parent schema. Partial schemas are not merged.

The same rules apply when you create an inheriting section via `inheritFromId` on `POST /documents/sections`.

<Note>Each section entry under `overrides.sections` must reference a section that is **already linked** to the base template version. You cannot add new sections via overrides — use [Path 3 (assembly)](/textgen/documents-guided-synthesis/path-3-assembly) for that.</Note>

## When to use this path

| Scenario                                                    | Why Path 2                                                                                                    |
| :---------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------ |
| Per-user UI customization on top of a stable template       | Drop the user-collected tweak straight into `templateRef.overrides`. No new resource per user.                |
| One-off adjustment to a Corti Standard or your own template | The base stays untouched; the auto-generated aggregate records exactly what was used.                         |
| You need traceability of what produced each document        | The response's `templateId` / `templateVersionId` point at the persisted aggregate; reference it for 30 days. |

## Related

<Columns cols={2}>
  <Card title="Guided Synthesis overview" href="/textgen/documents-guided-synthesis" icon="wand-sparkles">
    Shared concepts: input context, response shape, errors, 30-day retention.
  </Card>

  <Card title="Customization Cookbook — Recipe 3" href="/textgen/customization-cookbook/recipe-3-runtime-overrides-on-standards" icon="book-open">
    The end-user-driven pattern that maps directly onto Path 2 (presets vs. free-prompt).
  </Card>
</Columns>
