JsonPromptGenerator: nested object/array fields render as '[object Object]' in templates
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- tooling
Research direction
Start in src/prompt-generators/json.ts at buildVariables and reproduce the issue with the nested reporter and tags fields shown in the body. Add coverage for nested values through promptTemplate, then verify the generated prompt contains faithful field representations instead of [object Object] or comma-joined arrays.
Written by the indexing model from the issue text.
Description
Observed behavior
buildVariables in src/prompt-generators/json.ts coerces every top-level field of an object element to a string with a bare String(val):
for (const [key, val] of Object.entries(
element as Record<string, unknown>,
)) {
variables[key] = String(val);
}
When the JSON element contains nested objects or arrays - which is common in real API responses - the template variables for those keys silently become useless strings:
- A nested object becomes
[object Object]. - A nested array becomes its comma-joined
Array.prototype.toString()form, including nested-object members which themselves render as[object Object]. nullbecomes the literal stringnull.
The agent ends up with a garbled prompt and no warning that the data was lost.
Expected behavior
Either:
- Stringify nested values as JSON so the agent receives a faithful representation (for example
JSON.stringify(val)for non-string/number/boolean values), or - Throw a clear error when a referenced placeholder maps to a non-stringifiable value, so users know to pre-process their data or use
path/idFieldto flatten.
Option 1 is the lower-friction change and matches what users intuitively expect when iterating over a JSON file: any field they reference in the template appears in the prompt.
Minimal reproduction
import { JsonPromptGenerator } from 'loop-the-loop/prompt-generators/json';
import { LoopState } from 'loop-the-loop/util/loop-state';
const generator = await JsonPromptGenerator.create({
data: [
{
id: '1',
reporter: { name: 'Alice', team: 'Web' },
tags: ['bug', 'a11y'],
},
],
idField: 'id',
promptTemplate: 'Reporter: {{reporter}}, tags: {{tags}}',
});
for await (const prompt of generator.generate(new LoopState('ignored.json'))) {
console.log(prompt.prompt);
// → "Reporter: [object Object], tags: bug,a11y"
}
Suggested fix
In buildVariables, replace String(val) with a helper that stringifies non-scalars as JSON, for example:
function stringifyField(val: unknown): string {
if (val === null || val === undefined) {
return '';
}
if (typeof val === 'string') {
return val;
}
if (typeof val === 'number' || typeof val === 'boolean') {
return String(val);
}
return JSON.stringify(val);
}
Add a test that exercises a nested object field through promptTemplate.
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from joewalker/loop-the-loop
-
bug S4
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
joewalker/loop-the-loop#88 ·
-
Git exec(): child killed by a signal rejects with new Error('') and loses the signal information Openbug S3
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
joewalker/loop-the-loop#84 ·
-
bug S3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
joewalker/loop-the-loop#83 ·
-
bug S3
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
joewalker/loop-the-loop#82 ·
-
bug S4
Difficulty 1/5 Under an hour Newbie friendliness 90/100
joewalker/loop-the-loop#79 ·
All issues in joewalker/loop-the-loop
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100