Skip to content

[BUG] StructuredOutputHandler._fix_common_issues raises AttributeError when recovery_strategy is not a string #4318

Description

@Shxiao101

Version

0.2.91a7 (master @ d198715)

Description

In _fix_common_issues (camel/societies/workforce/structured_output_handler.py), the TaskAnalysisResult branch calls .lower() on recovery_strategy unconditionally:

strategy = fixed_data['recovery_strategy'].lower()

Weak models sometimes emit a non-string value for this field (e.g. "recovery_strategy": ["retry"] or 3). When that happens:

  1. schema(**extracted_data) raises ValidationError (expected).
  2. _fix_common_issues then raises AttributeError: 'list' object has no attribute 'lower' inside the except ValidationError handler.
  3. parse_structured_response only catches ValidationError, so the AttributeError propagates into the Workforce task-analysis flow and fails the whole run instead of falling back to fallback_values.

An unfixable string value already behaves correctly (left as-is → ValidationErrorfallback_values → default instance); only the non-string case crashes.

Reproduction

from camel.societies.workforce.structured_output_handler import StructuredOutputHandler
from camel.societies.workforce.utils import TaskAnalysisResult

StructuredOutputHandler.parse_structured_response(
    '{"reasoning": "task failed", "recovery_strategy": ["retry"]}',
    TaskAnalysisResult,
    fallback_values={"reasoning": "Defaulting to retry", "recovery_strategy": "retry"},
)
# AttributeError: 'list' object has no attribute 'lower'

Expected behavior

The best-effort fix path should never raise. Non-string values should be left as-is so validation fails into the caller's fallback_values (failure analysis defaults to RecoveryStrategy.RETRY), matching how unfixable string values already behave.

I have a small fix plus regression tests ready and will open a PR referencing this issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions