> ## 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 3 — Assemble from stored sections

> Build a template on the fly by referencing existing stored sections in declaration order. The resulting aggregate is auto-saved (30-day retention).

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

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

Use this when you don't have a template that matches your need, but you do have the sections. List the sections you want, in the order they should appear, and supply template-level instructions.

The response includes the new auto-generated template aggregate — keep its `templateId` to reuse the same composition on subsequent calls. The aggregate is **retained for 30 days only** (see [Auto-generated template aggregates — 30-day retention](/textgen/documents-guided-synthesis#auto-generated-template-aggregates-30-day-retention)); convert it into a permanent project-owned template if you want long-lived reuse.

<CodeGroup>
  ```ts title="JavaScript" expandable theme={null}
  // Replace these with your values
  const ALLERGIES_SECTION_ID = "<your-section-id>";
  const ASSESSMENT_SECTION_ID = "<your-section-id>";
  const HPI_SECTION_ID = "<your-section-id>";
  const INTERACTION_ID = "<your-interaction-id>";
  const PLAN_SECTION_ID = "<your-section-id>";
  const PLAN_VERSION_ID = "<your-version-id>";

  const result = await client.documents.generate({
    outputLanguage: "en-US",
    interactionId: INTERACTION_ID,
    assemblyTemplate: {
      name: "Allergy follow-up note",
      instructions: {
        prompt: "Produce a focused follow-up note for an allergy consultation.",
      },
      sectionRefs: [
        { sectionId: HPI_SECTION_ID },
        { sectionId: ALLERGIES_SECTION_ID },
        {
          sectionId: ASSESSMENT_SECTION_ID,
          overrides: {
            heading: "Impression",
            instructions: { writingStylePrompt: "Telegraphic; no narrative." },
          },
        },
        { sectionId: PLAN_SECTION_ID, sectionVersionId: PLAN_VERSION_ID },
      ],
    },
  });
  ```

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

  // Replace these with your values
  const string AllergiesSectionId = "<your-section-id>";
  const string AssessmentSectionId = "<your-section-id>";
  const string HpiSectionId = "<your-section-id>";
  const string InteractionId = "<your-interaction-id>";
  const string PlanSectionId = "<your-section-id>";
  const string PlanVersionId = "<your-version-id>";

  var result = await client.Documents.GenerateAsync(
      new GuidedDocumentsGenerateByAssembly
      {
          OutputLanguage = "en-US",
          InteractionId = InteractionId,
          AssemblyTemplate = new GuidedAssemblyRequest
          {
              Name = "Allergy follow-up note",
              Instructions = new GuidedTemplateInstructions
              {
                  Prompt = "Produce a focused follow-up note for an allergy consultation.",
              },
              SectionRefs = new[]
              {
                  new GuidedAssemblySectionRef { SectionId = HpiSectionId },
                  new GuidedAssemblySectionRef { SectionId = AllergiesSectionId },
                  new GuidedAssemblySectionRef
                  {
                      SectionId = AssessmentSectionId,
                      Overrides = new GuidedSectionOverrides
                      {
                          Heading = "Impression",
                          Instructions = new GuidedSectionInstructionsOverride
                          {
                              WritingStylePrompt = "Telegraphic; no narrative.",
                          },
                      },
                  },
                  new GuidedAssemblySectionRef
                  {
                      SectionId = PlanSectionId,
                      SectionVersionId = PlanVersionId,
                  },
              },
          },
      });
  ```

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

  # Replace these with your values
  ALLERGIES_SECTION_ID = "<your-section-id>"
  ASSESSMENT_SECTION_ID = "<your-section-id>"
  ENVIRONMENT = "<eu-or-us>"
  HPI_SECTION_ID = "<your-section-id>"
  INTERACTION_ID = "<your-interaction-id>"
  PLAN_SECTION_ID = "<your-section-id>"
  PLAN_VERSION_ID = "<your-version-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,
          "assemblyTemplate": {
              "name": "Allergy follow-up note",
              "instructions": {
                  "prompt": "Produce a focused follow-up note for an allergy consultation.",
              },
              "sectionRefs": [
                  {"sectionId": HPI_SECTION_ID},
                  {"sectionId": ALLERGIES_SECTION_ID},
                  {
                      "sectionId": ASSESSMENT_SECTION_ID,
                      "overrides": {
                          "heading": "Impression",
                          "instructions": {"writingStylePrompt": "Telegraphic; no narrative."},
                      },
                  },
                  {"sectionId": PLAN_SECTION_ID, "sectionVersionId": PLAN_VERSION_ID},
              ],
          },
      },
  )
  response.raise_for_status()
  result = response.json()
  ```

  ```bash title="cURL" expandable theme={null}
  # Replace these with your values
  ALLERGIES_SECTION_ID="<your-section-id>"
  ASSESSMENT_SECTION_ID="<your-section-id>"
  ENVIRONMENT="<eu-or-us>"
  HPI_SECTION_ID="<your-section-id>"
  INTERACTION_ID="<your-interaction-id>"
  PLAN_SECTION_ID="<your-section-id>"
  PLAN_VERSION_ID="<your-version-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}\",
      \"assemblyTemplate\": {
        \"name\": \"Allergy follow-up note\",
        \"instructions\": {
          \"prompt\": \"Produce a focused follow-up note for an allergy consultation.\"
        },
        \"sectionRefs\": [
          { \"sectionId\": \"${HPI_SECTION_ID}\" },
          { \"sectionId\": \"${ALLERGIES_SECTION_ID}\" },
          {
            \"sectionId\": \"${ASSESSMENT_SECTION_ID}\",
            \"overrides\": {
              \"heading\": \"Impression\",
              \"instructions\": { \"writingStylePrompt\": \"Telegraphic; no narrative.\" }
            }
          },
          { \"sectionId\": \"${PLAN_SECTION_ID}\", \"sectionVersionId\": \"${PLAN_VERSION_ID}\" }
        ]
      }
    }"
  ```
</CodeGroup>

## Behavior notes

* `sectionRefs` is **order-significant** — sections appear in the rendered document in declaration order.
* Each `sectionRef` resolves to the section's published version unless you pin `sectionVersionId`.
* `overrides` on a `sectionRef` follow the same partial/wholesale rules as [Path 2](/textgen/documents-guided-synthesis/path-2-templateref-overrides).

## When to use this path

| Scenario                                                                              | Why Path 3                                                                                                                                                                                                                     |
| :------------------------------------------------------------------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| EHR-field-driven note where the section set varies per encounter                      | Compose the right sections per call without authoring a template per combination.                                                                                                                                              |
| One document built from a few Corti Standard sections                                 | Skip the template authoring step entirely. The auto-generated aggregate is your "receipt."                                                                                                                                     |
| Customer-specific composition that you may eventually promote to a permanent template | Run Path 3 first; if the same composition recurs, convert the aggregate into a project-owned template via the [retention workaround](/textgen/documents-guided-synthesis#auto-generated-template-aggregates-30-day-retention). |

## 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="Create a Template" href="/textgen/template-creation" icon="puzzle">
    When you're ready to promote a recurring assembly into a stable, versioned template.
  </Card>
</Columns>
