Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q7 of 15
LangChain - Document Loading
What is wrong with this code snippet?
loader = SQLDatabaseLoader(connection_string='sqlite:///mydb.sqlite')
docs = loader.load()
print(docs[0].text)
Aload() returns a dictionary, so indexing is invalid
Bprint() cannot display Document objects
CThe connection string is missing a username
DThe Document object uses 'page_content' attribute, not 'text'
Step-by-Step Solution
Solution:
  1. Step 1: Understand Document object attributes

    Langchain Document objects store content in the 'page_content' attribute, not 'text'.
  2. Step 2: Check code usage

    Accessing docs[0].text will cause an attribute error; correct is docs[0].page_content.
  3. Final Answer:

    The Document object uses 'page_content' attribute, not 'text' -> Option D
  4. Quick Check:

    Document content attribute = page_content [OK]
Quick Trick: Use page_content to access Document text, not text [OK]
Common Mistakes:
  • Using .text instead of .page_content
  • Assuming load() returns dicts
  • Thinking print() can't show Document content

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes