Troubleshooting Variable Interpolation
Troubleshooting Variable Interpolation¶
This guide helps you diagnose and fix common variable interpolation issues in Prodigy workflows.
Issue: Variables Not Interpolating¶
Symptom: Literal ${var} or $VAR appears in output instead of the value.
Common Causes:
-
Variable name typo or case mismatch
-
Variable doesn't exist in current scope
-
Command failed before setting variable
Solutions:
- Check spelling and case sensitivity
- Verify variable exists in current phase (see phase availability table)
- Use verbose mode (-v) to see variable values during execution
- Echo variables to debug: shell: "echo 'DEBUG: var=${my_var}'"
Issue: Variable Empty or Undefined¶
Symptom: Variable interpolates but contains empty string or null.
Common Causes:
-
Variable used before being set
-
Command produced no output
-
Capture not configured
Solutions:
- Ensure capture_output is set when you need to save output
- Check command actually produces output
- Use verbose mode to see when variables are set
- Provide defaults: ${var:-default_value} (shell syntax)
Issue: Phase-Specific Variable Not Available¶
Symptom: Error about undefined variable or empty value when using phase-specific variables.
Common Causes:
| Variable | Wrong Phase | Correct Phase | Fix |
|---|---|---|---|
${item.*} |
Reduce, Setup, Merge | Map only | Use ${map.results} in reduce |
${map.*} |
Setup, Map, Merge | Reduce only | Move logic to reduce phase |
${merge.*} |
Setup, Map, Reduce | Merge only | Only use in merge commands |
Example Problem:
# Wrong - can't use ${item} in reduce
reduce:
- shell: "process ${item.name}" # ERROR!
# Correct - iterate through map.results
reduce:
- shell: "echo '${map.results}' | jq -r '.[] | .item.name' | while read name; do process \"$name\"; done"
Solutions:
- Review phase availability table in main Variables documentation
- Move variable usage to appropriate phase
- In reduce, access item data through ${map.results}
- Restructure workflow if necessary
Issue: Nested Field Access Fails¶
Symptom: Can't access nested JSON fields like ${var.field.nested}.
Common Causes:
-
Format not specified as JSON
# Wrong - no format specification - shell: "cargo metadata --format-version 1" capture_output: "metadata" - shell: "echo ${metadata.workspace_root}" # Won't work! # Correct - specify JSON format - shell: "cargo metadata --format-version 1" capture_output: "metadata" capture_format: "json" - shell: "echo ${metadata.workspace_root}" # Works! -
Field doesn't exist in JSON
-
JSON is invalid
Solutions:
- Always use capture_format: "json" for JSON output
- Verify JSON structure with jq: echo '${var}' | jq .
- Check field exists: echo '${var}' | jq -r '.field // "default"'
- Validate JSON before capture
Issue: Git Context Variables Empty¶
Symptom: Git variables like ${step.files_added} are empty.
Common Causes:
-
No commits created
-
Not in a git repository
-
No files changed in step
Solutions:
- Ensure commands that modify files use commit_required: true
- Verify you're in a git repository
- Check that commands actually modify files
- Use git status to verify changes exist
Issue: Format Modifiers Not Working¶
Symptom: Format modifiers like :json or :*.rs don't apply.
Common Causes:
-
Wrong variable type
-
Syntax error
Solutions:
- Format modifiers (:json, :lines, :csv, :*.ext) only work on git context variables
- For custom captures, use capture_format instead
- Check glob pattern syntax
Debugging Techniques¶
1. Use Verbose Mode¶
Verbose mode shows: - Variable values at each step - When variables are captured - Interpolated command strings before execution
2. Echo Variables for Debugging¶
- shell: "echo 'DEBUG: item=${item}'"
- shell: "echo 'DEBUG: item.path=${item.path}'"
- shell: "echo 'DEBUG: item_index=${item_index}'"
3. Check Claude JSON Logs¶
Claude command logs contain variable interpolation details:
# View most recent Claude command log
cat ~/.claude/projects/*/latest.jsonl | jq -c 'select(.type == "assistant")'
4. Verify Variables in Checkpoint Files¶
For resume issues, check checkpoint files:
5. Use jq to Explore JSON Variables¶
# Explore structure
- shell: "echo '${map.results}' | jq ."
# List available keys
- shell: "echo '${metadata}' | jq 'keys'"
# Pretty print
- shell: "echo '${item}' | jq -C ."
Common Syntax Issues¶
Issue: Special Characters in Variables¶
Problem:
Solution:
Issue: YAML String Escaping¶
Problem:
Solution:
Issue: Combining Variables with Text¶
Problem:
Solution:
# Use ${} syntax to clarify boundaries
- shell: "echo ${item}_path"
- shell: "echo prefix_${item}_suffix"
Best Practices for Avoiding Issues¶
- Always use
${VAR}syntax - More reliable than$VAR - Check phase availability - Review phase table before using variables
- Quote shell variables - Use
"${var}"in shell commands - Capture before use - Set
capture_outputbefore referencing - Specify JSON format - Use
capture_format: "json"for structured data - Use verbose mode - Debug with
-vflag - Validate JSON - Test with
jqbefore using in workflow - Document assumptions - Comment expected variable structure
- Provide fallbacks - Handle empty variables gracefully
- Test incrementally - Add variables one at a time
Getting Help¶
If you're still stuck after trying these debugging techniques:
- Check logs: Review Claude JSON logs for variable resolution
- Inspect checkpoints: Look at stored variable values
- Simplify workflow: Remove complexity to isolate issue
- Review examples: Check working examples in documentation
- Verify phase: Double-check variable is available in current phase
See Also: - Available Variables - Full variable reference with phase availability - Custom Variable Capture - Capture configuration and formats - Examples - Working examples of variable usage