Bird
0
0

Identify the error in this custom loader code:

medium📝 Debug Q14 of 15
LangChain - Document Loading
Identify the error in this custom loader code:
from langchain.document_loaders.base import BaseLoader

class FaultyLoader(BaseLoader):
    def load(self):
        docs = []
        docs.append('Just a string')
        return docs

loader = FaultyLoader()
loader.load()
AThe load method must be named read
BBaseLoader cannot be inherited directly
CThe class must not have a load method
DThe load method should return Document objects, not strings
Step-by-Step Solution
Solution:
  1. Step 1: Check what load returns

    The load method returns a list with a string instead of Document objects.
  2. Step 2: Recall Langchain expects Document objects

    Custom loaders must return Document instances, not plain strings, for proper processing.
  3. Final Answer:

    The load method should return Document objects, not strings -> Option D
  4. Quick Check:

    load() must return Document objects [OK]
Quick Trick: load() must return Document objects, not plain strings [OK]
Common Mistakes:
  • Returning strings instead of Document objects
  • Misnaming the load method
  • Thinking BaseLoader can't be inherited

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes