diff --git a/sdk/wren-langchain/src/wren_langchain/_format.py b/sdk/wren-langchain/src/wren_langchain/_format.py index 82d3085197..089a53964d 100644 --- a/sdk/wren-langchain/src/wren_langchain/_format.py +++ b/sdk/wren-langchain/src/wren_langchain/_format.py @@ -137,11 +137,21 @@ def format_list_models_content(manifest: dict[str, Any]) -> str: lines = ["| model | cols | description |", "|---|---|---|"] for m in models: - name = m.get("name", "") - col_count = len(m.get("columns", []) or []) - desc = ( - (m.get("properties") or {}).get("description") or m.get("description") or "" - ) + # MDL loaders / LLM-shaped manifests may include None rows, bare + # strings, or mixed types. Non-dicts previously AttributeError'd + # on ``.get`` and aborted the whole list_models content path. + if not isinstance(m, dict): + continue + name = m.get("name", "") or "" + columns = m.get("columns", []) or [] + if not isinstance(columns, list): + columns = [] + col_count = len(columns) + props = m.get("properties") or {} + if not isinstance(props, dict): + props = {} + desc = props.get("description") or m.get("description") or "" + desc = str(desc) # Trim long descriptions to keep table compact. if len(desc) > 80: desc = desc[:77] + "..." diff --git a/sdk/wren-langchain/tests/unit/test_format_list_models_guard.py b/sdk/wren-langchain/tests/unit/test_format_list_models_guard.py new file mode 100644 index 0000000000..4e8e2cda6e --- /dev/null +++ b/sdk/wren-langchain/tests/unit/test_format_list_models_guard.py @@ -0,0 +1,34 @@ +import importlib.util +from pathlib import Path + +_ROOT = Path(__file__).resolve().parents[2] +_PATH = _ROOT / "src" / "wren_langchain" / "_format.py" +_spec = importlib.util.spec_from_file_location("_fmt", _PATH) +_mod = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_mod) + + +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