fix(langchain): skip non-dict models in format_list_models_content - #2562
fix(langchain): skip non-dict models in format_list_models_content#2562Bartok9 wants to merge 2 commits into
Conversation
Malformed MDL rows (None/str/non-list columns) crashed the markdown table builder. Skip bad rows and coerce nested properties/columns.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Walkthrough
ChangesModel formatting safeguards
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@sdk/wren-langchain/tests/unit/test_format_list_models_guard.py`:
- Around line 11-25: Strengthen test_format_list_models_content coverage in
test_skips_non_dict_and_bad_nested by asserting the output does not contain “|
None |” or “| x |” anywhere, rather than checking one row position, and add a
model with a numeric or list description to verify non-string descriptions are
safely coerced while preserving the existing valid-row and truncation
assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: ea6b6d23-ebd5-4997-9171-5967dfedfe3d
📒 Files selected for processing (2)
sdk/wren-langchain/src/wren_langchain/_format.pysdk/wren-langchain/tests/unit/test_format_list_models_guard.py
| def test_skips_non_dict_and_bad_nested(): | ||
| out = _mod.format_list_models_content( | ||
| { | ||
| "models": [ | ||
| None, | ||
| "x", | ||
| {"name": "ok", "columns": None, "properties": "bad", "description": "d"}, | ||
| {"name": "wide", "columns": [1, 2], "properties": {"description": "y" * 100}}, | ||
| ] | ||
| } | ||
| ) | ||
| assert "| ok |" in out | ||
| assert "| wide |" in out | ||
| assert "None" not in out.split("\n")[2] | ||
| assert "..." in out |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Strengthen the regression assertions for the new guards.
The None assertion only inspects out.split("\n")[2], which is the ok row, so it does not prove malformed rows were skipped. The test also never exercises non-string description coercion. Assert | None | and | x | are absent, and add a numeric or list description case.
Suggested test adjustments
{"name": "ok", "columns": None, "properties": "bad", "description": "d"},
+ {"name": "typed", "properties": {"description": 123}},
{"name": "wide", "columns": [1, 2], "properties": {"description": "y" * 100}},
@@
- assert "None" not in out.split("\n")[2]
+ assert "| None |" not in out
+ assert "| x |" not in out
+ assert "| typed | 0 | 123 |" in out📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def test_skips_non_dict_and_bad_nested(): | |
| out = _mod.format_list_models_content( | |
| { | |
| "models": [ | |
| None, | |
| "x", | |
| {"name": "ok", "columns": None, "properties": "bad", "description": "d"}, | |
| {"name": "wide", "columns": [1, 2], "properties": {"description": "y" * 100}}, | |
| ] | |
| } | |
| ) | |
| assert "| ok |" in out | |
| assert "| wide |" in out | |
| assert "None" not in out.split("\n")[2] | |
| assert "..." in out | |
| def test_skips_non_dict_and_bad_nested(): | |
| out = _mod.format_list_models_content( | |
| { | |
| "models": [ | |
| None, | |
| "x", | |
| {"name": "ok", "columns": None, "properties": "bad", "description": "d"}, | |
| {"name": "typed", "properties": {"description": 123}}, | |
| {"name": "wide", "columns": [1, 2], "properties": {"description": "y" * 100}}, | |
| ] | |
| } | |
| ) | |
| assert "| ok |" in out | |
| assert "| wide |" in out | |
| assert "| None |" not in out | |
| assert "| x |" not in out | |
| assert "| typed | 0 | 123 |" in out | |
| assert "..." in out |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@sdk/wren-langchain/tests/unit/test_format_list_models_guard.py` around lines
11 - 25, Strengthen test_format_list_models_content coverage in
test_skips_non_dict_and_bad_nested by asserting the output does not contain “|
None |” or “| x |” anywhere, rather than checking one row position, and add a
model with a numeric or list description to verify non-string descriptions are
safely coerced while preserving the existing valid-row and truncation
assertions.
CI lint fails on ruff format --check for the new unit test.
|
Closing as superseded — non-dict model skipping in |
Summary
Skip non-dict model rows and coerce nested
columns/propertiesinformat_list_models_content.Real behavior proof
License
sdk/wren-langchain/**Apache-2.0.Summary by CodeRabbit
Bug Fixes
Tests