Render Agent Response Templates With Nested Variable Lookups

Last updated: November 29, 2026

Quick Overview

Implement render(template, ctx) that replaces placeholders like {{customer.name}} or {{orders.1.id}} with values from a nested dict and list context. Raise a clear error for missing paths and for unclosed or empty placeholders.

Sierra
Coding & Algorithms
Software Engineer
Sierra
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Implement render(template, ctx) that replaces placeholders like {{customer.name}} or {{orders.1.id}} with values from a nested dict and list context. Raise a clear error for missing paths and for unclosed or empty placeholders.

Sierra agents often fill structured messages, such as order confirmations, with data fetched from a customer's systems, and a silent blank in a customer-facing message is a real bug. The interviewer looks for a clean single-pass parser, careful index handling, and errors that fail loudly.

What the Interviewer Expects
  • Scan the string once using find instead of regex backtracking
  • Support dotted paths through dicts and numeric indices through lists
  • Raise on missing keys instead of rendering an empty string
  • Reject unclosed and empty placeholders
  • Keep literal text outside placeholders untouched
Key Topics to Cover
string parsing
nested lookup
error handling
templating
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you support a default value such as {{customer.nickname | 'there'}}?
  • How would you escape a literal {{ in output?
  • How would you prevent a template from reading fields the agent should not expose, such as a full card number?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Placeholders are {{ path }} with optional surrounding spaces. A path is dot-separated: dict keys, or non-negative integers when the current value is a list. Missing data raises KeyError(path). A `...

High-Level Design

Walk the template with an index i. Find the next {{; copy literal text before it; find the matching }}; resolve the path; append the value; continue after }}. Collect pieces in a list and join...


Submit Your Answer
Markdown supported

Related Questions