microsoft/semantic-kernel · error · ValueError

" ".join(violations)

Error message

" ".join(violations)

What it means

Raised by the Agenda plugin when one or more validation rules fail during an agenda update: total resource (turns) across items must equal the remaining amount, and every item must have a resource value greater than 0. All violations are collected and joined into a single ValueError message for the LLM.

Source

Thrown at python/samples/demos/guided_conversations/guided_conversation/plugins/agenda.py:234

                f"The total turns allocated in the agenda must not exceed the remaining amount ({remaining_turns})"
            )
            violations.append(f"{total_resource_instruction}; but the current total is {total_resources}.")

        # In exact mode if the total resources were not exactly equal to the remaining turns
        if (self.resource_constraint_mode == ResourceConstraintMode.EXACT) and (total_resources != remaining_turns):
            total_resource_instruction = (
                f"The total turns allocated in the agenda must equal the remaining amount ({remaining_turns})"
            )
            violations.append(f"{total_resource_instruction}; but the current total is {total_resources}.")

        # Check if any item has a resource value of 0
        if any(item["resource"] <= 0 for item in items):
            violations.append("All items must have a resource value greater than 0.")

        # Raise an error if any violations were found
        if len(violations) > 0:
            self.logger.debug(f"Agenda update failed due to the following violations: {violations}.")
            raise ValueError(" ".join(violations))

    def to_json(self) -> dict:
        agenda_dict = self.agenda.model_dump()
        return {
            "agenda": agenda_dict,
        }

    @classmethod
    def from_json(
        cls,
        json_data: dict,
        kernel: Kernel,
        service_id: str,
        resource_constraint_mode: ResourceConstraintMode | None,
        max_agenda_retries: int = 2,
    ) -> "Agenda":
        agenda = cls(kernel, service_id, resource_constraint_mode, max_agenda_retries)
        agenda.agenda.items = json_data["agenda"]["items"]

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Ensure the sum of item['resource'] across all agenda items equals the remaining turns.
  2. Ensure every item has resource > 0.
  3. Read the joined violation messages in the exception text — they state the expected total and which rule failed.
  4. Recompute the agenda from the current resource_constraint rather than guessing totals.

Example fix

// before
agenda.update({"items": [{"name": "intro", "resource": 0}, {"name": "body", "resource": 3}]}, remaining_turns=5)

// after
agenda.update({"items": [{"name": "intro", "resource": 2}, {"name": "body", "resource": 3}]}, remaining_turns=5)
Defensive patterns

Strategy: validation

Validate before calling

def validate_agenda(items: list[dict], remaining_turns: int) -> list[str]:
    violations = []
    total = sum(i.get('resource', 0) for i in items)
    if total != remaining_turns:
        violations.append(f'total {total} != remaining {remaining_turns}')
    if any(i.get('resource', 0) <= 0 for i in items):
        violations.append('all resources must be > 0')
    return violations
violations = validate_agenda(items, remaining_turns)
if violations:
    raise ValueError(' '.join(violations))

Type guard

def is_valid_agenda(items: list[dict], remaining_turns: int) -> bool:
    return (
        len(items) > 0
        and all(i.get('resource', 0) > 0 for i in items)
        and sum(i['resource'] for i in items) == remaining_turns
    )

Try / catch

try:
    agenda.update(payload, remaining_turns=remaining)
except ValueError as ex:
    # surface violations back to the model for correction
    corrections.append(str(ex))

Prevention

When it happens

Trigger: The LLM proposes an agenda whose item resource values do not sum to the remaining turns, or sets any item's resource to 0 or negative; from_json loading a malformed agenda payload.

Common situations: The model miscounts remaining turns; an agenda update payload is hand-crafted with wrong totals; resource_constraint changed but the agenda wasn't recomputed.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/42b37278720c9a3a. Report an issue: GitHub.