AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

HuggingFacePipeline._Generate Rejects Valid Translation Tasks Due To Substring Check

The `_generate` method uses `self.pipeline.task in "translation"` instead of an equality or prefix check, causing valid transformers translation tasks like `translation_en_to_fr` to raise ValueError. It also incorrectly matches empty string.

highConfidence 95%Langchain-HuggingfaceChat Modelslangchain-coreMemoryAffected V1.2.2

Origin Analysis

The condition `elif self.pipeline.task in "translation":` performs a substring check against the string `"translation"`. Since `"translation_en_to_fr"` is not a substring of `"translation"`, it falls through to the else branch and raises ValueError. Additionally, any string that is a substring of `"translation"` (including the empty string) will erroneously enter the translation branch.
Run the provided minimal example with a MagicMock pipeline whose `task` attribute is set to `"translation_en_to_fr"`. Calling `_generate` raises ValueError: Got invalid task translation_en_to_fr.

Fixing Code Block

Edge Case Audit

This monkey patch overrides the complete `_generate` method. If the original method included additional behavior (e.g., batch processing, stop sequence handling, or newer task types), those features are not replicated here and may be lost. The extraction key for `image-text-to-text` is assumed to be `generated_text`; if the actual pipeline output uses a different key, that branch must be adjusted. Apply this patch only as a temporary fix until an official release includes the correction. To rollback, remove the assignment `HuggingFacePipeline._generate = _generate` and restart the Python process or reload the module.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state