Fail fast on oversized plain LM prompts and clarify llm_query semantics#143
Open
taivu1998 wants to merge 1 commit into
Open
Fail fast on oversized plain LM prompts and clarify llm_query semantics#143taivu1998 wants to merge 1 commit into
taivu1998 wants to merge 1 commit into
Conversation
Author
|
Hi @alexzhang13, could you help review it when you have time? Thanks! |
1 similar comment
Author
|
Hi @alexzhang13, could you help review it when you have time? Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a fail-fast context-window guard for plain LM calls and clarifies when models should use
llm_query(...)versusrlm_query(...).Closes #42.
Problem
Issue #42 reports context-window failures when large prompts are sent through sub-calls. After reviewing the code path, the main practical gap was not child
RLMprompt inheritance, but plainllm_query(...)and leaf LM calls: they could send oversized prompts directly to provider SDKs with no preflight validation, which led to provider-specific failures and inconsistent error messages.What Changed
ContextWindowExceededErrorfor oversized prompt validation failures.rlm.utils.token_utils:estimate_text_tokens(...)count_prompt_tokens(...)validate_prompt_fits_context_window(...)LMHandlerand REPL error propagation path so validation errors surface cleanly insidellm_query(...)/rlm_query(...)fallback behavior.ContextWindowExceededErrorfrom the top-levelrlmpackage.llm_query(...)is for prompts that already fit the target model's context window.rlm_query(...)is the deeper/offloaded path where recursive subcalls are available.Design Notes
Tests
Added and updated tests for:
LMHandlerpropagation of context-window failuresLocalREPL/rlm_query(...)fallback error surfacing_subcallVerification
Result:
292 passed, 7 skipped