iflytek/astron-agent · warning · ValueError
Translation text cannot exceed 5000 characters
Error message
Translation text cannot exceed 5000 characters
What it means
The same `validate_text` pydantic validator caps translation input at 5000 characters and raises this ValueError when `len(value) > 5000`. Pydantic turns it into a ValidationError before the request reaches the upstream translation API, which itself has a length limit. It protects the service from oversized payloads the backend would reject anyway.
Solutions
- Split the input into chunks of at most 5000 characters and translate them sequentially or in parallel, then join results.
- Trim and optionally truncate input client-side before calling the API, warning the user about truncation.
- For long documents, use a document-translation path or summarize first instead of sending raw text.
- Count characters (including whitespace) exactly as Python's len() does to predict the limit.
Example fix
# before result = translate(text=huge_document) # 12000 chars # after CHUNK = 5000 chunks = [huge_document[i:i+CHUNK] for i in range(0, len(huge_document), CHUNK)] result = ''.join(translate(text=c) for c in chunks)
Defensive patterns
Strategy: validation
Validate before calling
const MAX = 5000;
if (text.length > MAX) {
// chunk or reject before calling
chunks = splitIntoChunks(text, MAX);
} Try / catch
try:
inp = TranslationInput(text=text, source_language=s, target_language=t)
except ValidationError as e:
if '5000' in str(e):
text = text[:5000]
inp = TranslationInput(text=text, source_language=s, target_language=t)
else:
raise Prevention
- Show a live character counter (limit 5000) in the translation UI.
- Chunk long documents client-side into <=5000-char pieces.
- Remember the limit counts all characters including whitespace.
When it happens
Trigger: Posting a TranslationInput whose `text` field is longer than 5000 characters (after no trimming — the length check counts the raw value, including leading/trailing whitespace).
Common situations: User pastes a long article/document into a translator UI; an upstream node passes a whole LLM response or file dump as text; concatenated paragraph assembly exceeds the limit unnoticed.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Translation text cannot be empty
- ragflow_ext is only allowed when ragType='Ragflow-RAG', got…
- Invalid group: . Valid options
- audio_data cannot be empty
- Invalid target language
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/8d9869f0a95a58d5.
Report an issue: GitHub.
Appendix: source
Thrown at core/plugin/aitools/service/translation/translation_service.py:50
class TranslationInput(BaseModel):
"""Translation input"""
text: str # Original text to be translated
target_language: str # Target language code
source_language: str = (
CHINESE_LANGUAGE_CODE # Source language code, default Chinese
)
@field_validator("text")
@classmethod
def validate_text(cls, value: str) -> str:
"""validate text"""
if not value or not value.strip():
raise ValueError("Translation text cannot be empty")
if len(value) > 5000:
raise ValueError("Translation text cannot exceed 5000 characters")
return value
@field_validator("target_language")
@classmethod
def validate_target_language(cls, value: str) -> str:
"""validate target language"""
if value not in VALID_LANGUAGE_CODES:
raise ValueError(
f"Invalid target language: {value}.\n"
f"Valid options: {list(VALID_LANGUAGE_CODES)}"
)
return value
@field_validator("source_language")
@classmethod
def validate_source_language(cls, value: str) -> str:
"""validate source language"""
if value not in VALID_LANGUAGE_CODES:View on GitHub (pinned to 5e758547a8)