Skip to content

Fix/Process content if the structuredContent are null#4252

Merged
brian-hussey merged 2 commits intomainfrom
fix/handle-structuredContent-null-path
Apr 16, 2026
Merged

Fix/Process content if the structuredContent are null#4252
brian-hussey merged 2 commits intomainfrom
fix/handle-structuredContent-null-path

Conversation

@msureshkumar88
Copy link
Copy Markdown
Collaborator

Fix OutputLengthGuard plugin null structuredContent handling

🔗 Related Issue

Closes #4248


📝 Summary

Fixed a bug in the OutputLengthGuard plugin where tool output was not being truncated when structuredContent was explicitly set to null. The plugin was checking for key presence but not validating the value, causing it to enter the structured content processing branch with a null value and skip content array processing entirely.

Changes:

  • Added null check to structuredContent key validation in output_length_guard.py (lines 249-254)
  • Added regression test test_null_structured_content_processes_content_array() to verify the fix

Impact:


🏷️ Type of Change

  • Bug fix
  • Feature / Enhancement
  • Documentation
  • Refactor
  • Chore (deps, CI, tooling)
  • Other (describe below)

🧪 Verification

Check Command Status
Lint suite make lint
Unit tests make test ✅ 315 passed, 1 skipped in 0.74s
Coverage ≥ 80% make coverage

Test Coverage:


✅ Checklist

  • Code formatted (make black isort pre-commit)
  • Tests added/updated for changes
  • Documentation updated (if applicable)
  • No secrets or credentials committed
  • DCO sign-off included in commits

📓 Notes

Root Cause

The plugin's logic checked for the presence of the structuredContent key but didn't validate whether the value was null:

# Before (buggy):
if "structuredContent" in result:
    struct_key = "structuredContent"

# After (fixed):
if "structuredContent" in result and result["structuredContent"] is not None:
    struct_key = "structuredContent"

When tools returned {"structuredContent": null, "content": [...]}, the plugin would:

  1. Detect the structuredContent key exists
  2. Enter the structured content processing branch
  3. Fail to process the null value
  4. Skip content array processing entirely

Testing

The new test verifies the exact scenario from issue #4248:

  • Tool returns structuredContent: null with a 63-character content array
  • Plugin configured with max_output_length: 10
  • Expected: Content truncated to 10 characters
  • Result: ✅ Content correctly truncated

Next Steps for Verification

  1. Restart the gateway to load the fixed plugin code
  2. Test with the echo tool - output should now truncate to 10 characters
  3. Verify in logs: "Plugin OutputLengthGuardPlugin executed successfully"

@msureshkumar88 msureshkumar88 added bug Something isn't working wxo wxo integration MUST P1: Non-negotiable, critical requirements without which the product is non-functional or unsafe plugins labels Apr 16, 2026
@msureshkumar88 msureshkumar88 changed the title process content if the structuredContent are null Fixprocess content if the structuredContent are null Apr 16, 2026
@msureshkumar88 msureshkumar88 changed the title Fixprocess content if the structuredContent are null Fix/ Process content if the structuredContent are null Apr 16, 2026
@msureshkumar88 msureshkumar88 changed the title Fix/ Process content if the structuredContent are null Fix/Process content if the structuredContent are null Apr 16, 2026
Copy link
Copy Markdown
Collaborator

@madhu-mohan-jaishankar madhu-mohan-jaishankar left a comment

Choose a reason for hiding this comment

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

LGTM.

ja8zyjits
ja8zyjits previously approved these changes Apr 16, 2026
Copy link
Copy Markdown
Member

@ja8zyjits ja8zyjits left a comment

Choose a reason for hiding this comment

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

LGTM

@ja8zyjits ja8zyjits added the release-fix Critical bugfix required for the release label Apr 16, 2026
Suresh Kumar Moharajan and others added 2 commits April 16, 2026 16:58
Signed-off-by: Suresh Kumar Moharajan <suresh.kumar.m@ibm.com>
Signed-off-by: Brian Hussey <brian.hussey@ie.ibm.com>
@brian-hussey brian-hussey force-pushed the fix/handle-structuredContent-null-path branch from 8649eaa to f4e6af7 Compare April 16, 2026 16:03
@brian-hussey brian-hussey self-assigned this Apr 16, 2026
@brian-hussey brian-hussey merged commit f025040 into main Apr 16, 2026
28 checks passed
@brian-hussey brian-hussey deleted the fix/handle-structuredContent-null-path branch April 16, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working MUST P1: Non-negotiable, critical requirements without which the product is non-functional or unsafe plugins release-fix Critical bugfix required for the release wxo wxo integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Output Length Guard Plugin not limiting different structs

4 participants