Mintplex-Labs/anything-llm · warning
\x1b[33m[.contextLimit warning]\x1b[0m Could not determine .
Error message
\x1b[33m[.contextLimit warning]\x1b[0m Could not determine .promptWindowLimit for provider ${provider}. This could lead to incorrect context window management by AnythingLLM since we cannot determine the context window limit for this provider/model combination. What it means
AiProvider.contextLimit resolved the provider class via getLLMProviderClass and either found nothing or the class lacks a promptWindowLimit static, so it returns a hard fallback of 8,000 tokens. All context management (history trimming, prompt sizing) for that provider/model will assume 8k, which under- or over-fills the real window.
Source
Thrown at server/utils/agents/aibitat/providers/ai-provider.js:565
/**
* Get the context limit for a provider/model combination using static method in AIProvider class.
* @param {string} provider
* @param {string} modelName
* @returns {number}
*/
static contextLimit(provider = "openai", modelName) {
if (typeof provider !== "string") {
console.log(
`\x1b[43m\x1b[30m[.contextLimit warning] A non-string provider for .contextLimit was given — Returning fallback context limit of 8000.\x1b[0m\n\x1b[43m\x1b[30mThis is a bug and should be reported so that context windows are properly managed by AnythingLLM.\x1b[0m`
);
console.trace();
return 8_000;
}
const llm = getLLMProviderClass({ provider });
if (!llm || !llm.hasOwnProperty("promptWindowLimit")) {
console.warn(
`\x1b[33m[.contextLimit warning]\x1b[0m Could not determine .promptWindowLimit for provider ${provider}. This could lead to incorrect context window management by AnythingLLM since we cannot determine the context window limit for this provider/model combination.`
);
return 8_000;
}
return llm.promptWindowLimit(modelName);
}
/**
* Get the system prompt for a provider, with memories appended (when enabled).
* @param {object} opts
* @param {import("@prisma/client").workspaces | null} opts.workspace
* @param {import("@prisma/client").users | null} opts.user
* @param {string} [opts.prompt] - current user message, used for reranking injected memories
* @returns {Promise<string>}
*/
static async systemPrompt({ workspace = null, user = null, prompt = "" }) {
const { SystemSettings } = require("../../../../models/systemSettings");
const { promptWithMemories } = require("../../../memories");View on GitHub (pinned to 20f6d3546c)
Solutions
- Verify the provider string is spelled exactly as registered in getLLMProviderClass.
- Add a static promptWindowLimit(modelName) to the provider class returning the correct token count.
- Register the provider class in getLLMProviderClass's map so the lookup succeeds.
- Until fixed, expect 8000 to be used — pick models whose real window is close or explicitly size prompts yourself.
Example fix
// before
class MyProvider extends Provider { /* no promptWindowLimit */ }
// after
class MyProvider extends Provider {
static promptWindowLimit(modelName = "my-model") {
return 128_000;
}
} Defensive patterns
Strategy: type-guard
Validate before calling
// When registering a provider, assert it supports context limits:
const cls = getLLMProviderClass({ provider: 'myprovider' });
if (!cls || !('promptWindowLimit' in cls)) {
throw new Error('provider class must implement static promptWindowLimit');
} Type guard
function hasPromptWindowLimit(cls) {
return !!cls && typeof cls.promptWindowLimit === 'function';
} Prevention
- Add a static promptWindowLimit(modelName) to every new provider class.
- Register the class under the exact provider key used in config.
- Unit-test contextLimit for each provider string you ship.
- Watch for this warning after provider refactors — it silently changes trimming behavior.
When it happens
Trigger: provider string not matching a known key of the provider registry (typo like 'opeanai'); a custom/new provider class added without a static promptWindowLimit(modelName) method; a provider registered under a different name than the one passed in.
Common situations: Contributing a new LLM provider and forgetting the limit method; swapping provider identifiers after a refactor; using a fork where the registry map was extended but the class was not.
Related errors
- No LocalAI Base Path was set.
- No LocalAi token context limit was set.
- Unknown provider: ${config.provider}. Please use a valid pro
- Type "${type}" is not a valid type to sync.
- QEMU directory not found: ${dir}\nContents of ${parent}: ${c
AI-assisted analysis of Mintplex-Labs/anything-llm@20f6d3546c (2026-08-18).
Data as JSON: /api/errors/8ecb39e5a971b58e.
Report an issue: GitHub.