xai-org/x-algorithm · error · IllegalArgumentException

Input user_states $str is invalid. Valid states are: " + Use

Error message

Input user_states $str is invalid. Valid states are: " + UserState.list

What it means

CandidateEvaluationBase parses the user_states argument: each comma/semicolon-separated string must map via UserState.valueOf to a known UserState. Invalid tokens trigger this IllegalArgumentException enumerating the valid states.

Source

Thrown at simclusters/simclusters_v2/scalding/evaluation/CandidateEvaluationBase.scala:39

    val validStateSet = validStates.toSet

    userStateSource
      .collect {
        case data if data.userState.isDefined && validStateSet.contains(data.userState.get) =>
          (data.userState.get, data.uid)
      }
      .filter(_ => Random.nextDouble() <= samplePercentage)
      .forceToDisk
  }

  def parseUserStates(strStates: Seq[String]): Seq[UserState] = {
    if (strStates.isEmpty) {
      UserState.list
    } else {
      strStates.map { str =>
        UserState
          .valueOf(str).getOrElse(
            throw new IllegalArgumentException(
              s"Input user_states $str is invalid. Valid states are: " + UserState.list
            )
          )
      }
    }
  }
}

trait UserStateBasedEvaluationExecutionBase
    extends CandidateEvaluationBase
    with TwitterExecutionApp {

  def referenceTweets: TypedPipe[ReferenceTweets]
  def candidateTweets: TypedPipe[CandidateTweets]

  override def job: Execution[Unit] = {
    Execution.withId { implicit uniqueId =>
      Execution.withArgs { args =>

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Check UserState.list (in the error message) and correct the token to a valid state name
  2. Trim whitespace and normalize case before comparing against UserState.valueOf
  3. If the state genuinely should exist, add it to the UserState enum in user-text-entity-regex or the owning lib

Example fix

// before
strStates.map { str =>
  UserState.valueOf(str).getOrElse(
    throw new IllegalArgumentException(s"Input user_states $str is invalid. Valid states are: " + UserState.list))
}

// after (fail fast with normalized tokens)
val validStates = UserState.list.map(s => s.toString.toLowerCase).toSet
val invalid = strStates.filterNot(s => validStates(s.trim.toLowerCase))
require(invalid.isEmpty, s"Invalid user_states: $invalid. Valid: ${UserState.list}")
Defensive patterns

Strategy: validation

Validate before calling

val valid = UserState.list.map(_.toString).toSet
val invalid = strStates.filterNot(valid)
require(invalid.isEmpty, s"Invalid user_states $invalid; valid: ${UserState.list}")

Type guard

def isValidUserState(s: String): Boolean = UserState.valueOf(s).isDefined

Prevention

When it happens

Trigger: Passing a user_states argument containing a token not in UserState (e.g. 'protected', 'suspennded'), while running the evaluation job.

Common situations: Typos in state names; states renamed/removed between code versions; copying state lists from another environment's job config.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/ca85f1b5194b32d8. Report an issue: GitHub.