Skip to content

fix(langchain): coerce None in format_store_content#2524

Open
Bartok9 wants to merge 1 commit into
Canner:mainfrom
Bartok9:fix/langchain-format-store-none-sql
Open

fix(langchain): coerce None in format_store_content#2524
Bartok9 wants to merge 1 commit into
Canner:mainfrom
Bartok9:fix/langchain-format-store-none-sql

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • format_store_content called .strip() on sql/nl without guarding None.
  • Coerce non-str nl/sql; treat non-list tags as zero tags.

Motivation

Store-tool confirmation paths can pass placeholders. formatting must not TypeError after a successful store.

License

sdk/** Apache-2.0

Verification

cd sdk/wren-langchain && python3 -m pytest tests/unit/test_format_store_content.py -v
# 3 passed

Test plan

  • Local unit tests
  • CI green

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of incomplete or unexpected stored content.
    • Prevented errors when SQL, natural-language text, or tags are missing or incorrectly formatted.
    • Ensured tag counts remain accurate for valid list-based tags.
  • Tests

    • Added coverage for normal content, missing values, and invalid tag formats.

Avoid TypeError when store-tool confirmation formats None placeholders
for nl/sql or a non-list tags argument.
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

format_store_content now safely handles non-string nl and sql values and counts tags only when tags is a list. Unit tests cover normal input, None values, and non-list tags.

Changes

Store content formatting

Layer / File(s) Summary
Input normalization and validation
sdk/wren-langchain/src/wren_langchain/_format.py, sdk/wren-langchain/tests/unit/test_format_store_content.py
Non-string text inputs become empty strings, non-list tags produce zero counts, and tests cover standard and invalid inputs.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Poem

I’m a rabbit with a tidy trail,
Empty strings keep errors frail.
Tags line up in lists so neat,
Tests hop through each case they meet.
Squeak—formatting’s now complete!

🚥 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: hardening format_store_content to coerce None inputs.
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.

🧹 Nitpick comments (1)
sdk/wren-langchain/tests/unit/test_format_store_content.py (1)

26-34: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover non-None non-string text inputs.

The tests exercise the None branches, but not the str(nl)/str(sql) coercion paths described by the PR objective. Add a case such as integers to prevent regressions.

Suggested test
+def test_format_store_content_non_string_text() -> None:
+    out = _fmt.format_store_content(123, 456, [])
+    assert 'Stored: "123"' in out
+    assert "456" 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_store_content.py` around lines 26 -
34, Add a unit test for format_store_content covering non-None, non-string nl
and sql inputs such as integers, and assert their string-coerced values appear
in the formatted output. Keep the existing None and non-list tag tests
unchanged.
🤖 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.

Nitpick comments:
In `@sdk/wren-langchain/tests/unit/test_format_store_content.py`:
- Around line 26-34: Add a unit test for format_store_content covering non-None,
non-string nl and sql inputs such as integers, and assert their string-coerced
values appear in the formatted output. Keep the existing None and non-list tag
tests unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b078faef-eb48-40cb-a599-638b3e1dd3d7

📥 Commits

Reviewing files that changed from the base of the PR and between 243eec8 and e9e522b.

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

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