Document Templates

Manage the DOCX and HTML templates used for automated document and proposal generation.

Note

For a high-level comparison of how templates and data schemas differ, see the Templates vs. Data Dictionaries overview.

Quickstart

Navigate to Settings > Document Templates to upload and manage your organization’s document templates.

In-Depth

Servantium uses standard Microsoft Word (DOCX) files and generated HTML code as templates. This allows you to maintain your brand’s exact styling, typography, and layout while automating the insertion of data.

Creating and Uploading

  1. Design your template in Microsoft Word.
  2. Use Merge Fields to indicate where data should be inserted (e.g., {{engagement.name}}, {{quote.total}}).
  3. In Servantium, go to Settings > Document Templates.
  4. Click Create. The system instantly generates a new template and redirects you directly to its workspace.
  5. On the template screen, rename the template to match its purpose.
  6. Optionally link an Example Engagement and an Example Quote. The system uses these to provide real data context to the AI during rendering tests.
  7. Optionally upload an Example Document (Word or PDF). The system securely stores this via internal Google Cloud Storage (gs://) URIs and provides it to the AI document templating agent as reference context. If you do not provide an example document, the system will warn you prior to generation that the AI might not produce a good result.
  8. Upload your master DOCX file, or configure raw markup directly in the HTML code editor. You can use the expand/collapse icon next to Template Details to hide the metadata header and maximize your workspace.
Caution

When manually configuring raw HTML templates, always use strict bracket notation for dictionary properties and nested structures (e.g., engagement['customData']['clientName'], NEVER engagement.customData.clientName). Using dot notation for dictionary keys like items, keys, or values causes fatal rendering crashes because Jinja2 resolves them to built-in Python methods. Additionally, always use proper Jinja closing tags (e.g., {% endif %} and {% else %}).

AI Template Generation

Servantium features intelligent AI agents that can automatically convert your example documents into reusable HTML/CSS templates.

  • Clean Sessions & Restarts: When you initiate AI generation, the system prompts you to “Start Fresh.” This explicitly forces a complete pipeline restart and clears any previous active AI session to ensure your new generation pipeline begins from a completely clean state.
  • Data Dictionary Generation: When configuring your prompt, you can check a box allowing the AI to automatically create or modify Custom Properties (Data Dictionaries). This ensures your underlying engagement schema is updated to support any new variables generated in the template.
  • Live Data Context: By selecting an Example Engagement and Example Quote, the QA agent performs full data rendering tests against your actual records instead of using generic mock data.
  • Multimodal Extraction: When you upload an example document, the backend multimodal AI processes the file, extracting text via OCR and identifying assets (like logos). The generation pipeline automatically pre-fetches these structural blueprints and assets, injecting them directly into the Developer agents to prevent AI hallucinations and ensure they are reliably inserted into the final HTML. If no example document is linked to the template, the generation dialog will display a warning that the AI might not produce a good result.
  • Side-by-Side Code Editor: The workspace dynamically adapts to your screen size. On desktop, it displays a side-by-side layout containing your original reference document, the HTML code editor, and a live HTML preview. On mobile, these panels are organized into tabs. This dedicated code editor provides an improved developer experience for configuring and refining the final template markup, and features a live preview that updates in real-time as you code. To optimize performance, the live HTML preview automatically pauses when dialogs are open or when you are actively typing or focusing the AI input box. Press Cmd+F (Mac) or Ctrl+F (Windows) to search; highlighting text beforehand automatically populates the search field, and matches are smoothly centered on screen. Use the clear button to quickly reset your search.
  • Visual, Syntax & Data QA: The Developer and QA agents proactively parse Jinja syntax to extract variables, cross-referencing them against the live data schema to manually verify nested properties and eliminate hallucinations. Dedicated HTML and Visual QA agents perform full data rendering tests against actual engagement data to ensure the template compiles successfully. Finally, they run a visual pass to check if the generated HTML visually matches the source document. To guarantee completeness, output validators explicitly reject any generated HTML that contains truncation placeholders (like ... or [truncated]), forcing the AI to provide the exact, full code block. If QA identifies syntax errors, hallucinated variables, or missing sections, it explicitly rejects the template and directly injects the exact rejection feedback into the Developer agent prompt. The orchestrator then selectively regenerates only the failed sections rather than the entire document. For layout or visual mismatches, the system injects feedback into the Stitcher agent to force precise corrections to the global CSS. To prevent infinite processing loops, the system caps automated correction retries at three attempts before advancing to the summary and manual review phase.
  • Parallel HTML Generation: To handle massive documents efficiently, the AI outlines the structural sections and spins up specialized Developer and QA agents to build them in parallel. To ensure precise content preservation, Developer agents are strictly prohibited from generating raw text or narrative content. Their only job is to write bare-bones semantic HTML with class names around Jinja tags and include short static text (like labels and headers). For standard sections, they explicitly omit all inline styles. However, if a section requires a highly unique layout (such as an absolute-positioned cover page or complex graphics), the developer agent will generate scoped CSS specifically for that block. Finally, a Stitcher agent compiles the document by generating the master HTML wrapper. The pipeline automatically pre-fetches the global CSS stylesheet (extracted from the original PDF’s typography, colors, and layout) to prevent styling hallucinations. The Stitcher acts as the global CSS stylist for the entire document, and uses an automated tag (__INJECT_SECTIONS_HERE__) to safely inject the completed blocks. This prevents content hallucinations and drastically improves generation speed and reliability.
  • Interactive Workflow Tracking: During generation, an interactive, zoomable directed graph visually tracks pipeline progress. The graph automatically adapts to your system’s light or dark mode preferences. It intelligently maps complex internal sub-agents (like schema mappers and section orchestrators) into logical, high-level UI steps for cleaner tracking. Upon completion (or if an error occurs), the conversational summary and diagnostic messages appear inline alongside the graph as selectable text, making it easy to copy diagnostic information.
  • Interactive Feedback Loop: After the summary, the generation pipeline pauses to wait for your feedback. You can also use this feature at any time to modify manually written templates. Hover, click, or focus the floating ‘Ask Gemini’ box in the bottom right corner of the screen to provide a natural language request (e.g., “Fix the table formatting in the Deliverables section”). The input box automatically expands to give you plenty of space to type. For manually written raw HTML, the AI skips the initial generation and routes your request directly into this feedback loop. A Feedback Agent orchestrates the request, evaluates which components need to be updated based on context, and concurrently routes it to the necessary expert sub-agents: Quotes (for pricing or calculations), Engagements (for form fields), Snippets (for reusable text), Data Dictionaries (for repeatable custom properties), HTML (for visual layout, CSS, or static wording changes), or Schemas (strictly for massive structural mapping overhauls). For HTML fixes, the agent automatically extracts the specific section name from the document outline, allowing the orchestrator to selectively regenerate only the targeted block rather than the entire document. Static wording vs snippets: Short, static wording changes that do not change from document to document (e.g., changing “Prepared for” to “Proposal for”, or fixing typos in headers) are routed as HTML changes. update_snippet is strictly reserved for dynamic AI narrative blocks or massive static legal blocks, preventing unnecessary structural schema overhauls. To ensure your requests are accurately addressed, HTML QA agents perform strict feedback verification. They explicitly cross-reference the generated HTML against your requested changes, rejecting the update if your feedback was omitted or ignored. To ensure rapid iterations, the feedback loop bypasses time-consuming visual QA for HTML fixes and skips QA entirely for quote, engagement, snippet, or data dictionary updates. The pipeline concludes by routing directly to the Summary agent for a revised overview of the final changes. You can also explicitly instruct the agent to run QA tests to verify compilation without altering the underlying markup.

AI Snippet Extraction

During generation, the AI extracts content into three distinct snippet types:

  • Text: Static text that remains identical across every document (e.g., legal language, company history).
  • AI: Dynamic text generated on the fly for each specific project.
  • AI HTML: Complex, dynamic diagrams and structural formatting. The AI strictly uses this type for large document sections like Deliverables or Assumptions to preserve structural HTML formatting.

The AI follows strict extraction mapping rules:

  1. HTML to Snippets: Any HTML content is always mapped to a snippet (text or aiHtml), never to custom data fields.
  2. Complete Content Coverage: Long blocks of narrative text and all major sections are mapped to AI snippets. Short static labels or document headers (e.g., “Proposal For”, “Total Cost”) are explicitly NOT snippets; they are hardcoded directly into the semantic HTML template. The AI is strictly instructed not to skip, summarize, or omit any sections (including appendices, testimonies, or resumes), ensuring it creates structural HTML blocks for every snippet and replicates the full length of the original document.
  3. Pricing to Quotes: Pricing tables, financial calculations, fixed fees, and total project costs are mapped directly into Quote Templates as explicit line items, never into snippets or custom data. When building the HTML for these sections, the AI is explicitly instructed to iterate over quote.sections and line items rather than attempting to render static variables.
  4. Missing Snippets: If the AI cannot find a requested snippet, it uses a logical Jinja placeholder (e.g., {{ snippet['deliverables'] }}) instead of hardcoding the text or hallucinating fallbacks.

How it works

When a user generates a document from an engagement or quote, the backend merging engine:

  1. Fetches the template.
  2. Scans for all merge fields.
  3. Resolves those fields using data from the specific Engagement, Quote, Organization, and the User’s Profile.
  4. Generates a final, ready-to-send PDF or DOCX file.
Note

For a complete list of available merge fields and advanced formatting options (like tables and conditional logic), refer to the Documents Guide.

Need more help?

Our support team is available to assist you.

Contact Support