BerriAI/litellm · warning · ValueError
Cannot specify both maxChunkCount and maxDocumentCount.
Error message
Cannot specify both maxChunkCount and maxDocumentCount.
What it means
GroundingSearchConfig, part of the SAP grounding module config, allows limiting search by maxChunkCount or maxDocumentCount but not both - they are mutually exclusive per the SAP Generative AI Hub API. A Pydantic model_validator (mode='after') raises this ValueError when both fields are non-None.
Source
Thrown at litellm/llms/sap/chat/models.py:153
class KeyValueListPair(BaseModel):
key: str
value: list[str]
class DocumentMetadataKeyValueListPairs(KeyValueListPair):
select_mode: list[Literal["ignoreIfKeyAbsent"]] | None = None
class GroundingSearchConfig(BaseModel):
max_chunk_count: int | None = Field(default=None, ge=0)
max_document_count: int | None = Field(default=None, ge=0)
@model_validator(mode="after")
def validate_max_chunk_count_and_max_document_count(self):
if self.max_chunk_count is not None and self.max_document_count is not None:
raise ValueError("Cannot specify both maxChunkCount and maxDocumentCount.")
return self
class DocumentGroundingFilter(BaseModel):
id_: str | None = Field(default=None, alias="id")
data_repository_type: Literal["vector", "help.sap.com"]
search_config: GroundingSearchConfig | None = None
data_repositories: list[str] | None = None
data_repository_metadata: list[KeyValueListPair] | None = None
document_metadata: list[DocumentMetadataKeyValueListPairs] | None = None
chunk_metadata: list[KeyValueListPair] | None = None
class DocumentGroundingPlaceholders(BaseModel):
input: list[str] = Field(min_length=1)
output: str
View on GitHub (pinned to 77b7c6c40c)
Solutions
- Keep exactly one of the two limits; delete the other from the config dict.
- If you need tighter cost control, prefer max_document_count for broad recall budgets or max_chunk_count for per-chunk granularity.
- Validate configs with the Pydantic model in a unit test before deploying request templates.
Example fix
# before GroundingSearchConfig(max_chunk_count=5, max_document_count=10) # after GroundingSearchConfig(max_document_count=10)
Defensive patterns
Strategy: validation
Validate before calling
def build_search_config(max_chunk_count=None, max_document_count=None) -> dict:
if max_chunk_count is not None and max_document_count is not None:
raise ValueError('set only one of max_chunk_count / max_document_count')
cfg = {}
if max_chunk_count is not None:
cfg['max_chunk_count'] = max_chunk_count
if max_document_count is not None:
cfg['max_document_count'] = max_document_count
return cfg Prevention
- Expose only one limit knob in your config schema.
- Run a Pydantic validation pass over the full module config in unit tests.
When it happens
Trigger: Building a DocumentGroundingFilter with GroundingSearchConfig(max_chunk_count=N, max_document_count=M) - both set - in the grounding module config of a sap/ completion request.
Common situations: Copy-pasting full search-config examples from SAP docs into code; teams tuning grounding costs and setting both limits 'to be safe'; config generators that emit every optional field.
Related errors
- For SAP Masking Module Config you must set exactly one of: '
- Content must be a string
- For SAP Masking Module Config you must provide 'providers'.
- For using SAP Filtering Module you must provide at least one
- TranslationModuleConfig requires at least one of 'input' or
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/84d245668eafbb5d.
Report an issue: GitHub.