Skip to content

Blob.as_bytes_io() raises NotImplementedError for string data #36667

@chang923

Description

@chang923

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

#36666

Reproduction Steps / Example Code (Python)

from langchain_core.documents.base import Blob

blob = Blob.from_data("hello")
with blob.as_bytes_io() as f:
    print(f.read())

Error Message and Stack Trace (if applicable)

NotImplementedError: Unable to convert blob Blob 0x... metadata={} data='hello'

Description

I'm trying to use Blob.as_bytes_io() on a blob created with string data. I expect it to return a byte stream of the string, just like as_bytes() does. Instead, it raises NotImplementedError.

This is an API inconsistency: as_string() and as_bytes() both work with string data, but as_bytes_io() does not.

System Info

System Information

OS: Linux
OS Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024
Python Version: 3.10.20 (main, Mar 11 2026, 17:46:40) [GCC 14.3.0]

Package Information

langchain_core: 1.2.19
langchain: 1.2.13
langchain_community: 0.4.1
langsmith: 0.7.17
langchain_chroma: 1.1.0
langchain_classic: 1.0.3
langchain_deepseek: 1.0.1
langchain_huggingface: 1.2.1
langchain_openai: 1.1.11
langchain_text_splitters: 1.1.1
langgraph_sdk: 0.3.11

Optional packages not installed

deepagents
deepagents-cli

Other Dependencies

aiohttp: 3.13.3
async-timeout: 4.0.3
chromadb: 1.5.5
dataclasses-json: 0.6.7
httpx: 0.28.1
httpx-sse: 0.4.3
huggingface-hub: 1.7.1
jsonpatch: 1.33
langgraph: 1.1.2
numpy: 2.2.6
openai: 2.28.0
opentelemetry-api: 1.40.0
opentelemetry-sdk: 1.40.0
orjson: 3.11.7
packaging: 25.0
pydantic: 2.12.5
pydantic-settings: 2.13.1
pytest: 9.0.3
pyyaml: 6.0.3
PyYAML: 6.0.3
requests: 2.32.5
requests-toolbelt: 1.0.0
rich: 14.3.3
sentence-transformers: 5.3.0
sqlalchemy: 2.0.48
SQLAlchemy: 2.0.48
tenacity: 9.1.4
tiktoken: 0.12.0
tokenizers: 0.22.2
transformers: 5.3.0
typing-extensions: 4.15.0
uuid-utils: 0.14.1
websockets: 16.0
xxhash: 3.6.0
zstandard: 0.25.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugRelated to a bug, vulnerability, unexpected error with an existing featurecore`langchain-core` package issues & PRsexternal

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions