{"record":{"id":"84d245668eafbb5d","repo":"BerriAI/litellm","slug":"cannot-specify-both-maxchunkcount-and-maxdocumentc","errorCode":null,"errorMessage":"Cannot specify both maxChunkCount and maxDocumentCount.","messagePattern":"Cannot specify both maxChunkCount and maxDocumentCount\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"litellm/llms/sap/chat/models.py","lineNumber":153,"sourceCode":"\n\nclass KeyValueListPair(BaseModel):\n    key: str\n    value: list[str]\n\n\nclass DocumentMetadataKeyValueListPairs(KeyValueListPair):\n    select_mode: list[Literal[\"ignoreIfKeyAbsent\"]] | None = None\n\n\nclass GroundingSearchConfig(BaseModel):\n    max_chunk_count: int | None = Field(default=None, ge=0)\n    max_document_count: int | None = Field(default=None, ge=0)\n\n    @model_validator(mode=\"after\")\n    def validate_max_chunk_count_and_max_document_count(self):\n        if self.max_chunk_count is not None and self.max_document_count is not None:\n            raise ValueError(\"Cannot specify both maxChunkCount and maxDocumentCount.\")\n        return self\n\n\nclass DocumentGroundingFilter(BaseModel):\n    id_: str | None = Field(default=None, alias=\"id\")\n    data_repository_type: Literal[\"vector\", \"help.sap.com\"]\n    search_config: GroundingSearchConfig | None = None\n    data_repositories: list[str] | None = None\n    data_repository_metadata: list[KeyValueListPair] | None = None\n    document_metadata: list[DocumentMetadataKeyValueListPairs] | None = None\n    chunk_metadata: list[KeyValueListPair] | None = None\n\n\nclass DocumentGroundingPlaceholders(BaseModel):\n    input: list[str] = Field(min_length=1)\n    output: str\n\n","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/sap/chat/models.py#L135-L171","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nGroundingSearchConfig(max_chunk_count=5, max_document_count=10)\n# after\nGroundingSearchConfig(max_document_count=10)","handlingStrategy":"validation","validationCode":"def build_search_config(max_chunk_count=None, max_document_count=None) -> dict:\n    if max_chunk_count is not None and max_document_count is not None:\n        raise ValueError('set only one of max_chunk_count / max_document_count')\n    cfg = {}\n    if max_chunk_count is not None:\n        cfg['max_chunk_count'] = max_chunk_count\n    if max_document_count is not None:\n        cfg['max_document_count'] = max_document_count\n    return cfg","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Expose only one limit knob in your config schema.","Run a Pydantic validation pass over the full module config in unit tests."],"tags":["sap","grounding","validation","mutually-exclusive"],"backgroundTag":"mutually-exclusive-parameters","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}