Skip to content

Comments

fix: Enhance LLM tip generation robustness #56

Merged
gjt-prog merged 5 commits intoAgentToolkit:mainfrom
gjt-prog:fix-tip-empty-messages
Feb 19, 2026
Merged

fix: Enhance LLM tip generation robustness #56
gjt-prog merged 5 commits intoAgentToolkit:mainfrom
gjt-prog:fix-tip-empty-messages

Conversation

@gjt-prog
Copy link
Collaborator

@gjt-prog gjt-prog commented Feb 12, 2026

Enhance LLM tip generation robustness by skipping empty assistant messages and handling malformed/empty responses, and add validation for trajectory data.

Summary by CodeRabbit

  • Bug Fixes

    • Skips empty or unexpected assistant messages instead of failing.
    • Tip generation now safely handles empty, malformed, or invalid responses and returns an empty result rather than erroring.
  • Chores

    • Added warnings-level logging for empty or problematic assistant responses to aid troubleshooting.

…t messages and handling malformed/empty responses, and add validation for trajectory data.
@coderabbitai
Copy link

coderabbitai bot commented Feb 12, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Added a module logger and improved error handling in kaizen/llm/tips/tips.py: parse_openai_agents_trajectory now skips empty/unrecognized assistant messages instead of raising, and generate_tips logs and returns [] for empty responses, JSON parse errors, and validation errors.

Changes

Cohort / File(s) Summary
Error Handling & Logging
kaizen/llm/tips/tips.py
Added logging (uses logger = logging.getLogger(__name__)), introduced Path and ValidationError imports. parse_openai_agents_trajectory now skips empty/non-list assistant content instead of raising. generate_tips logs warnings and returns [] for empty clean_response, JSONDecodeError, and ValidationError during parsing/validation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐇 I nibble at JSON crumbs and leave a note,
A quiet log where tangled bytes once smote.
I hop past empties, errors I dismiss,
Safer trails traced in lines of gentle hiss. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: Enhance LLM tip generation robustness' accurately and specifically describes the main change in the pull request, which adds error handling and robustness to the LLM tip generation functionality.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@kaizen/llm/tips/tips.py`:
- Around line 152-156: Wrap the call to
TipGenerationResponse.model_validate(json.loads(clean_response)) in an
additional except block that catches pydantic.ValidationError (import
ValidationError from pydantic alongside other imports), log a warning similar to
the JSONDecodeError case using logger.warning with the error and a truncated
repr(clean_response[:500]), and return [] so the function gracefully handles
schema validation failures; ensure the new except references
TipGenerationResponse.model_validate, logger.warning, and clean_response.
🧹 Nitpick comments (2)
kaizen/llm/tips/tips.py (2)

78-80: Consider logging when skipping non-empty assistant content.

The previous code raised an exception for unrecognized content, which served as an alert for unexpected data shapes. Silently continuing is fine for empty/None content, but if content is a non-empty, non-string, non-list value (e.g., a dict or unexpected type), this will now silently discard it. A debug-level log would help surface unexpected content shapes without breaking the flow.

💡 Suggested improvement
             else:
-                # Skip empty assistant messages (common from tool-calling patterns)
-                continue
+                # Skip empty assistant messages (common from tool-calling patterns)
+                if content:
+                    logger.debug(f"Skipping unexpected assistant content type: {type(content).__name__}")
+                continue

5-5: Logger name "entities-mcp" looks like it belongs to a different module.

The conventional Python pattern is logging.getLogger(__name__), which would yield "kaizen.llm.tips.tips" and integrate naturally with hierarchical logger configuration. Using a hardcoded name from an unrelated namespace makes filtering and log routing confusing.

💡 Suggested fix
-logger = logging.getLogger("entities-mcp")
+logger = logging.getLogger(__name__)

visahak
visahak previously approved these changes Feb 16, 2026
@visahak
Copy link
Collaborator

visahak commented Feb 16, 2026

LGTM.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@kaizen/llm/tips/tips.py`:
- Line 16: The module-level logger is created with a hardcoded name
"entities-mcp" which is incorrect; update the logger instantiation in tips.py
(the logger variable) to use the module's __name__ (logging.getLogger(__name__))
so logs inherit the package logger hierarchy and are attributable to
kaizen.llm.tips.tips instead of a copy-pasted name.

@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2026

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{"name":"HttpError","status":401,"request":{"method":"PATCH","url":"https://api.github.com/repos/AgentToolkit/kaizen/issues/comments/3893850410","headers":{"accept":"application/vnd.github.v3+json","user-agent":"octokit.js/0.0.0-development octokit-core.js/7.0.6 Node.js/24","authorization":"token [REDACTED]","content-type":"application/json; charset=utf-8"},"body":{"body":"<!-- This is an auto-generated comment: summarize by coderabbit.ai -->\n<!-- This is an auto-generated comment: failure by coderabbit.ai -->\n\n> [!CAUTION]\n> ## Review failed\n> \n> An error occurred during the review process. Please try again later.\n\n<!-- end of auto-generated comment: failure by coderabbit.ai -->\n\n<!-- walkthrough_start -->\n\n<details>\n<summary>📝 Walkthrough</summary>\n\n## Walkthrough\n\nAdded a module logger and replaced several raise paths with safe skips in `parse_openai_agents_trajectory`. `generate_tips` now logs and returns empty lists for empty responses, JSON decode errors, and validation errors instead of raising.\n\n## Changes\n\n|Cohort / File(s)|Summary|\n|---|---|\n|**Error Handling & Logging** <br> `kaizen/llm/tips/tips.py`|Added `logging` and `logger = logging.getLogger(\"entities-mcp\")`. `parse_openai_agents_trajectory` skips empty/unrecognized assistant messages instead of raising. `generate_tips` logs and returns `[]` for empty `clean_response`, wraps JSON parsing/validation in try/except, logs warnings on `JSONDecodeError`/`ValidationError`, and returns `[]` on failures.|\n\n## Estimated code review effort\n\n🎯 2 (Simple) | ⏱️ ~12 minutes\n\n## Poem\n\n> 🐰 I sniff the logs where broken JSON hides,  \n> I hop past empty echoes and tangled tides.  \n> A gentle warning, then onward I roam,  \n> Safer paths logged — a rabbit's small home. 🥕\n\n</details>\n\n<!-- walkthrough_end -->\n\n<!-- pre_merge_checks_walkthrough_start -->\n\n<details>\n<summary>🚥 Pre-merge checks | ✅ 2 | ❌ 1</summary>\n\n### ❌ Failed checks (1 warning)\n\n|     Check name     | Status     | Explanation                                                                           | Resolution                                                                         |\n| :----------------: | :--------- | :------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------- |\n| Docstring Coverage | ⚠️ Warning | Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |\n\n<details>\n<summary>✅ Passed checks (2 passed)</summary>\n\n|     Check name    | Status   | Explanation                                                                                                                                                                                   |\n| :---------------: | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled.                                                                                                                                   |\n|    Title check    | ✅ Passed | The title 'fix: Enhance LLM tip generation robustness' directly and clearly summarizes the main change: improving the robustness of LLM tip generation through error handling and validation. |\n\n</details>\n\n<sub>✏️ Tip: You can configure your own custom pre-merge checks in the settings.</sub>\n\n</details>\n\n<!-- pre_merge_checks_walkthrough_end -->\n\n<!-- finishing_touch_checkbox_start -->\n\n<details>\n<summary>✨ Finishing touches</summary>\n\n<details>\n<summary>🧪 Generate unit tests (beta)</summary>\n\n- [ ] <!-- {\"checkboxId\": \"f47ac10b-58cc-4372-a567-0e02b2c3d479\", \"radioGroupId\": \"utg-output-choice-group-unknown_comment_id\"} -->   Create PR with unit tests\n- [ ] <!-- {\"checkboxId\": \"07f1e7d6-8a8e-4e23-9900-8731c2c87f58\", \"radioGroupId\": \"utg-output-choice-group-unknown_comment_id\"} -->   Post copyable unit tests in a comment\n\n</details>\n\n</details>\n\n<!-- finishing_touch_checkbox_end -->\n\n<!-- tips_start -->\n\n---\n\nThanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=AgentToolkit/kaizen&utm_content=56)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.\n\n<details>\n<summary>❤️ Share</summary>\n\n- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)\n- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)\n- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)\n- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)\n\n</details>\n\n<sub>Comment `@coderabbitai help` to get the list of available commands and usage tips.</sub>\n\n<!-- tips_end -->\n\n<!-- internal state start -->\n\n\n<!-- DwQgtGAEAqAWCWBnSTIEMB26Cu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y8eN50WKVFaqxSsitxyopQGKlJrQbcF/mrPUwrJU/VFDiegUBbxKBsNw9QgBMAmQAgIgsBEYkCkAdPSbDMYwJUF4WgGgjWKpVYpZgnFhUpxlsGBNqrcWpngDZNskrNVsGFUoBlIpx6kNVQAX2NZAZV2bFLqpWUW7VXBFJEq8IwQ1tbcVmpyJiq1PbqW2vtfvYVcBIjiGJZEAA5H4QIkAQhDUeDEeIiRtTaVzgqJU+REAzp8guNCHhbRUIYHzCgx7mLPlEu6MuSIvoYNIFwJyFx3y2XntkXIu7qGrs1Ekem+9FZZGwEGrMcdMxDRGrZHKu9O56njUO5Nqa23ptlkQLNDbCS+j8EQOsbLIXWqTbm/NHhC1auFVOrwlaVU1sTfWk1Ta5gtp1R8vGtlbxArdBhk1faLU/II4hkdmAx1toRQwNjVwmCcdIFGyolINAWIAKSegQG8KNFoHA+D8AwZcToNAwCVrOeci4gPSBeauKNxSFOUkUwhxNuL8yzDwF2YV5t1CRFoKxvsZVCqZjLptV4epkBDPPCGb0zAxz2E7IgHw8gy5SeUDJi6+ZzNxu40mlNSg02D3Q4h4jFoC3ouY22zz4nvMouo3UKtLMG6isUuK3AthdXlsdW2wxSiOnhNUT4Mx8T2lUlZGgckJAlFoGqCQSotAmmNMSQwdJNJSkqF60eXpXIIiqJG3NrkiSGTJKsQIDD9W7SNZsB21tw7ElWKsZN1R1RqiqIEFSKxXImmmPybQRJ1SlGmIqWgKxe1fGqJ0QIWpzT4lcloPo9Je1qijfJJdqxtB1GHdKxJjjiWSC9Q5mrDwaJiTfPo9SkSYkJIeCkkzGSTM5KyAJ/Z6lBB0QeGhltIL3zySIYC9tP0pt+hiYk3xhkibqtVYMNVxRHjZnzMWYxsRUz3EQEotVLeeUZHohoKruRmytlHdyFYNAeVaBjFwNKiR4yzlDNwLeeauBbmUjFwI/XBAlf65qmakgkyqH6CAA=== -->\n\n<!-- internal state end -->"},"request":{"retryCount":1}},"response":{"url":"https://api.github.com/repos/AgentToolkit/kaizen/issues/comments/3893850410","status":401,"headers":{"access-control-allow-origin":"*","access-control-expose-headers":"ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset","connection":"close","content-security-policy":"default-src 'none'","content-type":"application/json; charset=utf-8","date":"Tue, 17 Feb 2026 15:42:57 GMT","referrer-policy":"origin-when-cross-origin, strict-origin-when-cross-origin","server":"github.com","strict-transport-security":"max-age=31536000; includeSubdomains; preload","vary":"Accept-Encoding, Accept, X-Requested-With","x-content-type-options":"nosniff","x-frame-options":"deny","x-github-media-type":"github.v3; format=json","x-github-request-id":"9090:30DFE0:1DE72:80903:69948C81","x-xss-protection":"0"},"data":{"message":"Bad credentials","documentation_url":"https://docs.github.com/rest","status":"401"}}}

visahak
visahak previously approved these changes Feb 17, 2026
@gjt-prog gjt-prog merged commit d2a4d0a into AgentToolkit:main Feb 19, 2026
15 checks passed
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.

3 participants