Skip to content

Conversation

@majiayu000
Copy link

Summary

When tools receive primitive values (strings, numbers) as input, the toolInput field in intermediateSteps was incorrectly set to an empty object {}. This fix wraps primitive values in an object with an input key, ensuring the tool input is properly exposed.

The issue: In buildSteps.ts, when toolInput.input is a primitive value (like a string "5*343"), the condition typeof toolInputForResult === 'object' fails, resulting in an empty {} being returned instead of the actual input.

The fix: Added logic to wrap primitive values in { input: value } format, making the input accessible in intermediateSteps.

Related Issue

Fixes #23501

Test plan

  • Added test case for primitive string input ("5*343")
  • Added test case for primitive number input (42)
  • All existing tests pass
  • TypeScript type check passes

When tools receive primitive values (strings, numbers) as input, the
toolInput field in intermediateSteps was incorrectly set to an empty
object. This fix wraps primitive values in an object with an 'input'
key, ensuring the tool input is properly exposed.

Fixes n8n-io#23501

Signed-off-by: majiayu000 <1835304752@qq.com>
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/@n8n/nodes-langchain/utils/agent-execution/buildSteps.ts">

<violation number="1" location="packages/@n8n/nodes-langchain/utils/agent-execution/buildSteps.ts:259">
P2: Rule violated: **Prefer Typeguards over Type casting**

Type narrowing with `as IDataObject` should use a type guard function instead. After the `typeof === &#39;object&#39;` check, TypeScript knows it&#39;s an object but not specifically `IDataObject`. Consider creating a type guard function or using assertion function to properly narrow the type.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

// - Otherwise, return empty object
let resultToolInput: IDataObject;
if (toolInputForResult && typeof toolInputForResult === 'object') {
resultToolInput = toolInputForResult as IDataObject;
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Rule violated: Prefer Typeguards over Type casting

Type narrowing with as IDataObject should use a type guard function instead. After the typeof === 'object' check, TypeScript knows it's an object but not specifically IDataObject. Consider creating a type guard function or using assertion function to properly narrow the type.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/@n8n/nodes-langchain/utils/agent-execution/buildSteps.ts, line 259:

<comment>Type narrowing with `as IDataObject` should use a type guard function instead. After the `typeof === &#39;object&#39;` check, TypeScript knows it&#39;s an object but not specifically `IDataObject`. Consider creating a type guard function or using assertion function to properly narrow the type.</comment>

<file context>
@@ -250,13 +250,24 @@ export function buildSteps(
+			// - Otherwise, return empty object
+			let resultToolInput: IDataObject;
+			if (toolInputForResult &amp;&amp; typeof toolInputForResult === &#39;object&#39;) {
+				resultToolInput = toolInputForResult as IDataObject;
+			} else if (toolInputForResult !== undefined &amp;&amp; toolInputForResult !== null) {
+				// Handle primitive values like strings or numbers
</file context>
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

intermediateSteps "toolInput" is empty despite "log" showing the input

1 participant