Debug Template Validation Errors
Template errors can prevent document generation or produce unexpected output. This guide helps you identify and resolve common template validation errors.
Enabling Error Display
Inline Errors (Recommended for Development)
Enable “Inline template syntax errors” in the Build a Doc action:
- Errors appear in the output document instead of failing the action
- Helps identify exactly where errors occur
- Useful during template development
Error Messages
When inline errors are disabled, errors are returned in the action failure response.
Common Syntax Errors
Missing Closing Brackets
Error: Unexpected end of tag
Cause: Tag not properly closed
Wrong:
<<[CustomerName>Correct:
<<[CustomerName]>>Unclosed Loops
Error: Unclosed foreach block
Cause: Missing <</foreach>> tag
Wrong:
<<foreach [item in Items]>><<[item.Name]>>Correct:
<<foreach [item in Items]>><<[item.Name]>><</foreach>>Unclosed Conditionals
Error: Unclosed if block
Cause: Missing <</if>> tag
Wrong:
<<if [ShowDiscount]>>Discount appliedCorrect:
<<if [ShowDiscount]>>Discount applied<</if>>Data Binding Errors
Invalid Property Path
Error: Invalid path: 'Custmer.Name'
Cause: Typo in property name or path doesn’t exist
Fix: Verify the path matches your JSON structure exactly (case-sensitive)
Null Reference
Error: Null reference at 'Customer.Address.City'
Cause: Parent object is null
Fix: Ensure data is populated, and add null checks or ensure data is populated:
<<if [Customer.Address]>><<[Customer.Address.City]>><</if>>Type Mismatch
Error: Cannot convert 'string' to 'number'
Cause: Attempting numeric operations on string values
Fix: Ensure data types match expected operations
Loop Errors
Invalid Iterator
Error: Invalid iterator expression
Cause: Malformed foreach syntax
Wrong:
<<foreach [Items]>>Correct:
<<foreach [item in Items]>>Array Not Found
Error: 'Items' is not an array
Cause: Property is not an array or doesn’t exist
Fix: Verify the property exists and is an array in your data source
Debugging Techniques
Step 1: Isolate the Problem
- Remove complex sections temporarily
- Test with minimal template
- Add sections back gradually to find the issue
Step 2: Validate JSON Data
- Use a JSON validator tool
- Ensure structure matches template expectations (see Structure JSON Data)
- Check for special characters that might need escaping
Step 3: Check Property Paths
- List all placeholders in your template
- Verify each path exists in your JSON
- Check capitalisation matches exactly
Step 4: Test in Add-in
- Use the Word Add-in preview feature
- Errors display immediately
- Faster iteration than full Power Automate testing
Error Reference Table
| Error | Cause | Solution |
|---|---|---|
| Unexpected end of tag | Missing >> | Close all tags with >> |
| Unclosed foreach block | Missing <</foreach>> | Add closing foreach tag |
| Unclosed if block | Missing <</if>> | Add closing if tag |
| Invalid path | Property doesn’t exist | Check spelling and structure |
| Null reference | Parent object is null | Add null checks |
| Type mismatch | Wrong data type | Verify data types |
| Invalid expression | Syntax error in expression | Check expression syntax |
Prevention Tips
- Use consistent naming - Follow a naming convention for properties
- Validate data first - Check data structure before template processing
- Test incrementally - Don’t wait until the end to test
- Keep templates simple - Break complex logic into data preparation
- Use version control - Track template changes