BerriAI/litellm · error · ValueError
Invalid `pages` list for Azure Document Intelligence: {pages
Error message
Invalid `pages` list for Azure Document Intelligence: {pages!r}. Expected tokens like '1' or '3-5'. What it means
Raised when `pages` is a list of strings but the comma-joined result fails Azure's page-range regex — i.e. the individual tokens are not plain page numbers or hyphenated ranges. List[str] input is treated as Azure-native 1-based tokens, stripped, joined, and validated as a whole before being sent. Tokens like '1..3', '1;', 'page1', or an empty string trigger this.
Source
Thrown at litellm/llms/azure_ai/ocr/document_intelligence/transformation.py:164
f"Invalid `pages` string for Azure Document Intelligence: "
f"{pages!r}. Expected format like '1-3,5,7-9'."
)
return pages.replace(" ", "")
if isinstance(pages, list):
if len(pages) == 0:
return ""
if any(isinstance(p, bool) for p in pages):
raise ValueError("`pages` must be integers, not booleans")
if all(isinstance(p, int) for p in pages):
if any(p < 0 for p in pages):
raise ValueError("`pages` integers must be >= 0 (Mistral 0-based indices)")
# Mistral 0-based -> Azure 1-based.
return ",".join(str(p + 1) for p in sorted(set(pages)))
if all(isinstance(p, str) for p in pages):
joined: Final = ",".join(p.strip() for p in pages)
if not pages_pattern.match(joined):
raise ValueError(
f"Invalid `pages` list for Azure Document Intelligence: "
f"{pages!r}. Expected tokens like '1' or '3-5'."
)
return joined
raise ValueError("`pages` must be a list[int] (0-based, Mistral-style) or a string like '1-3,5,7-9'.")
@staticmethod
def _normalize_features_param(features: object) -> str:
"""
Convert a caller-provided `features` value to Azure DI's query-string
form (comma-joined feature names, e.g. "keyValuePairs,languages").
Accepted inputs:
- list[str]: feature names like ["keyValuePairs", "languages"].
- str: a single feature name or comma-separated names.
"""
invalid_features_error: Final = ValueError(View on GitHub (pinned to 6c2dcb801b)
Solutions
- Use tokens that are single 1-based page numbers or ranges: ['1', '3-5'] or ['1-3', '7'].
- If you have 0-based indices, switch to list[int] and let LiteLLM convert.
- Validate/clean tokens before the call: strip whitespace, drop empties, ensure digits-only or digit-digit.
Example fix
# before
pages = [p.strip() for p in user_input.split(",") if True] # may leave '' or '1..2'
litellm.aocr_document(model=..., document=doc, pages=pages)
# after
import re
pages = [p.strip() for p in user_input.split(",") if re.fullmatch(r"\d+(-\d+)?", p.strip())]
litellm.aocr_document(model=..., document=doc, pages=pages) Defensive patterns
Strategy: validation
Validate before calling
import re
TOKEN_RE = re.compile(r"^\d+(-\d+)?$")
def valid_pages_tokens(pages: list[str]) -> bool:
return all(isinstance(p, str) and TOKEN_RE.match(p.strip()) for p in pages) Type guard
def is_str_pages_list(v: object) -> bool:
import re
return isinstance(v, list) and all(
isinstance(p, str) and re.fullmatch(r"\d+(-\d+)?", p.strip()) for p in v
) Prevention
- Validate each token with ^\d+(-\d+)?$ after stripping.
- Drop empty tokens when splitting a user string on commas.
When it happens
Trigger: Calling azure_ai doc-intelligence OCR with pages=["1..3"], ["1", ""], ["page 2"], or ["1-3", "abc"] — any list[str] whose joined form doesn't match ^\d+(-\d+)?(,\d+(-\d+)?)*$ after stripping.
Common situations: Splitting a user-supplied string on commas without validating tokens (leaving empties); forwarding tokens from another API's syntax; shell/env-var parsing inserting stray characters.
Related errors
- Invalid `pages` string for Azure Document Intelligence: {pag
- `pages` integers must be >= 0 (Mistral 0-based indices)
- `pages` must be integers, not booleans
- `pages` must be a list[int] (0-based, Mistral-style) or a st
- Expected document dict, got {type(document)}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/0975e8c5b1edbd7b.
Report an issue: GitHub.