Scrapegraph-ai: KeyError: 'Input to PromptTemplate is missing variables

Describe the bug I am trying to run the code example in your README but I always encounter the following error: KeyError: 'Input to PromptTemplate is missing variables {\'"content"\'}. Expected: [\'"content"\', \'question\'] Received: [\'question\']\nNote: if you intended {"content"} to be part of the string and not a variable, please escape it with double curly braces like: \'{{"content"}}\'.\nFor troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/INVALID_PROMPT_INPUT '

To Reproduce Steps to reproduce the behavior: Copy the code example in the README and run it.

Expected behavior Not getting an error.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: WSL
  • Browser Chromium
  • Version 155

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context I am running with scrapegraphai==1.39.0

from scrapegraphai.graphs import SmartScraperGraph

# Define the configuration for the scraping pipeline
graph_config = {
    "llm": {"model": "ollama/llama3.2", "model_tokens": 8192},
    "verbose": True,
    "headless": False,
}

# Create the SmartScraperGraph instance
smart_scraper_graph = SmartScraperGraph(
    prompt="Extract useful information from the webpage, including a description of what the company does, founders and social media links",
    source="https://scrapegraphai.com/",
    config=graph_config,
)

# Run the pipeline
result = smart_scraper_graph.run()

import json

print(json.dumps(result, indent=4))

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 19
  • Comments: 17 (1 by maintainers)

Most upvoted comments

Hey there, @amitschendel! I’m here to assist you with any bugs, questions, or contributions. Let’s tackle this issue together!

The error you’re encountering indicates that the PromptTemplate is missing the "content" variable in its input. The PromptTemplate expects both "content" and "question" variables, but it seems only "question" is being provided.

To resolve this issue, ensure that the "content" variable is included in the input when initializing the PromptTemplate. Here’s a general approach to fix it:

  1. Check the part of the code where the PromptTemplate is being initialized.
  2. Make sure that both "content" and "question" are provided in the input_variables or partial_variables.

For example, if your code looks like this:

prompt = PromptTemplate(
    template=TEMPLATE_SEARCH_WITH_CONTEXT_CHUNKS,
    input_variables=["question"],
    partial_variables={
        "context": chunk.page_content,
        "format_instructions": format_instructions,
    },
)

Ensure that "content" is included in the partial_variables or input_variables as needed. If "content" is a fixed value, you can add it to partial_variables like this:

prompt = PromptTemplate(
    template=TEMPLATE_SEARCH_WITH_CONTEXT_CHUNKS,
    input_variables=["question"],
    partial_variables={
        "content": your_content_value,  # Add this line
        "context": chunk.page_content,
        "format_instructions": format_instructions,
    },
)

If "content" is dynamic, ensure it is passed correctly when the template is used. Adjust your code accordingly to include the "content" variable.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

I am facing the same issue, managed to work it out with downgrading the library to scrapegraphai==1.37.0 with pip3 install scrapegraphai==1.37.0 its varsion from January, need to check what have changed since then.

facing the same error, but with different attribute names, while running examples

KeyError: 'Input to PromptTemplate is missing variables {'“foo”', '“$defs”', '“properties”'}. Expected: ['“$defs”', '“foo”', '“properties”', 'question'] Received: ['question']\nNote: if you intended {“foo”} to be part of the string and not a variable, please escape it with double curly braces like: '{{“foo”}}'.\nFor troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/INVALID_PROMPT_INPUT ’