LLM Parameter Filtering#
ScrapeGraphAI's _create_llm() method in AbstractGraph constructs LLM client instances from a user-supplied llm config dict. Several keys in that dict are ScrapeGraphAI-internal β consumed by the framework and meaningless (or actively harmful) to underlying LangChain/provider constructors. These keys must be removed before the dict is splatted into a provider class or init_chat_model().
Internal Parameters That Are Filtered#
| Parameter | Where removed | Why |
|---|---|---|
rate_limit | line 134 β llm_params.pop("rate_limit", {}) | Converted to a rate_limiter object; raw dict must not reach the client |
model_tokens | After line 222 (see PR #1100 below) β llm_params.pop("model_tokens", None) | Stored in self.model_token for chunk-size accounting; not a recognized LLM API parameter |
model_provider | line 243 β llm_params.pop("model_provider") | Routing key used by ScrapeGraphAI; popped before custom provider constructors are called |
temperature (Bedrock only) | line 237 β llm_params.pop("temperature") | Moved into model_kwargs for the Bedrock-specific API shape |
The model_tokens Bug and Fix (PR #1100)#
The model_tokens key was a known leakage point. On the plain llm-config path, _create_llm() reads the value into self.model_token but, before the fix, never removed it from llm_params. When init_chat_model(**llm_params) was then called, model_tokens was forwarded to the underlying model client, producing:
TypeError: Completions.create() got an unexpected keyword argument 'model_tokens'. Did you mean 'max_tokens'?
PR #1100 fixes this with a single pop and explanatory comment immediately after self.model_token is set:
# Consumed by ScrapeGraphAI; must not be forwarded to the model client.
llm_params.pop("model_tokens", None)
This mirrors the behavior on the model_instance path , which returns early before any keys can reach the provider.
How Filtering Is Structured (No Central Utility)#
There is no centralized filter list or utility function. Filtering is ad-hoc inside _create_llm(), with each internal key popped at the appropriate point in the method's flow:
rate_limitβ popped early at the top of the methodmodel_tokensβ popped after token count is resolved (after line 222)model_providerβ popped in the custom-provider branch before constructing the wrapper
The model_instance key is effectively filtered by the early-return at β if model_instance is present, the method returns immediately and llm_params is never passed to any constructor.
Implications for Adding New Providers#
Any new custom provider branch added to _create_llm() must:
- Pop
model_provider(already done at line 243 before the branch). - Pop
model_tokensbefore callingProviderClass(**llm_params). - Pop any other ScrapeGraphAI-specific keys present in
llm_paramsat that point.
Failure to do so will cause a TypeError at runtime when the provider constructor receives an unexpected keyword argument β exactly the bug described in PR #1100 .