iflytek/astron-agent · error · ValueError

Cannot provide both fileUrl and file parameters

Error message

Cannot provide both fileUrl and file parameters

What it means

Raised by _validate_split_parameters (core/knowledge/service/impl/ragflow_strategy.py:195) when split() receives both fileUrl and a file object. The two input sources are mutually exclusive: the strategy cannot decide which one to upload to RAGFlow, so it rejects the request up front.

Solutions

  1. Send exactly one input — remove fileUrl if you have a file object, or drop the file if you intend to fetch from fileUrl.
  2. In the API layer, clear/ignore fileUrl whenever a multipart file part is present before calling split().
  3. In UI code, disable or clear the URL field once a file is selected (and vice versa).

Example fix

// before
chunks = await strategy.split(fileUrl=url, **{"file": f})  # both set

// after
if f is not None:
    chunks = await strategy.split(**{"file": f})
else:
    chunks = await strategy.split(fileUrl=url)
Defensive patterns

Strategy: validation

Validate before calling

def resolve_single_input(fileUrl, file):
    if fileUrl and file:
        raise ValueError("fileUrl and file are mutually exclusive")
    return file if file else fileUrl

Type guard

def exactly_one_input(fileUrl, file) -> bool:
    return bool(bool(file) != bool(fileUrl))

Try / catch

try:
    chunks = await strategy.split(fileUrl=fileUrl, **{"file": file})
except ValueError as e if "both" in str(e):
    # prefer the uploaded file, retry without URL
    chunks = await strategy.split(**{"file": file})

Prevention

When it happens

Trigger: Calling strategy.split(fileUrl='https://...', **{'file': uploaded_file}); also when an API handler merges form fields and multipart file into the same kwargs dict, unintentionally setting both.

Common situations: A frontend 'upload or link' form where the user both picked a file and left a previously-typed URL in place; middleware that defaults fileUrl to a placeholder while also attaching the file; programmatic callers copying kwargs from another strategy that allows both.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/d88733f72fa3fac0. Report an issue: GitHub.

Appendix: source

Thrown at core/knowledge/service/impl/ragflow_strategy.py:195

        )
        if effective_top_k and effective_top_k > 0:
            results = results[:effective_top_k]

        logger.info("Query completed, returning %d results", len(results))
        return {"query": query, "count": len(results), "results": results}

    def _empty_query_result(self, query: str) -> Dict[str, Any]:
        """Unified empty-result format for query paths."""
        return {"query": query, "count": 0, "results": []}

    def _validate_split_parameters(
        self, fileUrl: Optional[str], file: Optional[Any]
    ) -> None:
        """Validate split method parameters."""
        if not fileUrl and not file:
            raise ValueError("Either fileUrl or file must be provided")
        if fileUrl and file:
            raise ValueError("Cannot provide both fileUrl and file parameters")

    def _parse_form_data_parameters(
        self,
        lengthRange: Optional[List[int]],
        separator: Optional[List[str]],
        cutOff: Optional[List[str]],
    ) -> tuple[Optional[List[int]], Optional[List[str]], Optional[List[str]]]:
        """Parse form-data parameters from JSON strings."""
        parsed_length_range = lengthRange
        parsed_separator = separator
        parsed_cut_off = cutOff

        if isinstance(lengthRange, str):
            try:
                parsed_length_range = json.loads(lengthRange) if lengthRange else None
            except (json.JSONDecodeError, TypeError):
                parsed_length_range = None

View on GitHub (pinned to 5e758547a8)