Skip to content

fix(langchain): skip non-dict models in format_list_models_content - #2562

Closed
Bartok9 wants to merge 2 commits into
Canner:mainfrom
Bartok9:fix/langchain-list-models-non-dict-20260722
Closed

fix(langchain): skip non-dict models in format_list_models_content#2562
Bartok9 wants to merge 2 commits into
Canner:mainfrom
Bartok9:fix/langchain-list-models-non-dict-20260722

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Skip non-dict model rows and coerce nested columns/properties in format_list_models_content.

Real behavior proof

$ python3 -m pytest sdk/wren-langchain/tests/unit/test_format_list_models_guard.py -v
1 passed

License

sdk/wren-langchain/** Apache-2.0.

Summary by CodeRabbit

  • Bug Fixes

    • Improved model list rendering when manifest entries contain invalid or unexpected data.
    • Safely skips malformed/non-standard entries so the full model list doesn’t fail to display.
    • More robust handling of nested fields and descriptions, including consistent text formatting and safer truncation.
  • Tests

    • Added unit test coverage for mixed invalid models, malformed nested fields, and truncated output behavior.

Malformed MDL rows (None/str/non-list columns) crashed the markdown
table builder. Skip bad rows and coerce nested properties/columns.
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 94b023c6-2265-45b0-8d66-6f5c654a79e2

📥 Commits

Reviewing files that changed from the base of the PR and between 6a311c8 and 59d358d.

📒 Files selected for processing (1)
  • sdk/wren-langchain/tests/unit/test_format_list_models_guard.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • sdk/wren-langchain/tests/unit/test_format_list_models_guard.py

Walkthrough

format_list_models_content now tolerates malformed manifest models and nested fields, with unit tests covering filtering and rendering behavior.

Changes

Model formatting safeguards

Layer / File(s) Summary
Guard malformed model entries and validate rendering
sdk/wren-langchain/src/wren_langchain/_format.py, sdk/wren-langchain/tests/unit/test_format_list_models_guard.py
Non-dictionary models are skipped; columns, properties, and descriptions are normalized before rendering. Tests cover malformed entries, valid model rows, and ellipsis truncation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: python

Poem

A bunny found models in a muddled array,
And skipped the odd shapes along the way.
Columns grew tidy, descriptions took flight,
Good rows appeared in the table just right.
“Hop!” said the rabbit, “the formatter’s bright!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: skipping non-dict model entries in format_list_models_content.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 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

📥 Commits

Reviewing files that changed from the base of the PR and between f4b45ed and 6a311c8.

📒 Files selected for processing (2)
  • sdk/wren-langchain/src/wren_langchain/_format.py
  • sdk/wren-langchain/tests/unit/test_format_list_models_guard.py

Comment on lines +11 to +25
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 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.

Suggested change
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.
@Bartok9

Bartok9 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded — non-dict model skipping in format_list_models_content already landed on main via #2521. Branch conflicts with no remaining unique fix.

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.

1 participant