Skip to main content

Fixed: An Adaptive Card Number Input in Teams Changes to Its Maximum Instead of Showing the Error Message

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

An Adaptive Card number box allowed 1 to 4, with an error message for anything else. In Microsoft Teams, I typed 6 and waited for the message. It never came: when I left the box, the 6 turned into a 4, and the card sent 4 to the agent.

What I Was Doing​

I was testing a card for an agent in Teams: a ticket order with one Input.Number that accepts 1 to 4 tickets. The card set min, max and an errorMessage, so that Teams could stop a wrong number before it reached the agent:

Cards/tickets.json
{
"type": "AdaptiveCard",
"version": "1.5",
"body": [
{ "type": "TextBlock", "text": "Concert tickets", "size": "Large", "weight": "Bolder" },
{
"type": "Input.Number",
"id": "tickets",
"label": "Tickets (1 to 4)",
"min": 1,
"max": 4,
"value": 1,
"errorMessage": "Pick from 1 to 4 tickets."
}
],
"actions": [
{ "type": "Action.Submit", "title": "Buy", "data": { "card": "tickets" } }
]
}

The agent, built with the Microsoft 365 Agents SDK, sends the card and replies with the values the card sends back.

What I Expected​

Type 6, select Buy, and see Pick from 1 to 4 tickets. under the box, with nothing sent.

What I Got​

While I typed, the box showed 6:

The Concert tickets card in Teams with 6 typed in the Tickets (1 to 4) box, which is still focused, and the Buy button below

When I left the box, it showed 4, with no message:

The same card after leaving the box: the Tickets (1 to 4) box now shows 4, with no error message

And Buy sent 4. Teams added its Your response was sent to the app note, and the agent's reply showed what it got:

The card with 4 in the box and Teams' note Your response was sent to the app, and below it the agent's reply The card sent: card tickets, tickets 4

What the agent received
{"card":"tickets","tickets":"4"}

Below the minimum, it was the same in the other direction: 0 turned into 1. The error message didn't show either way.

What I Checked​

That it wasn't my test. I typed 6 with the keyboard, the way a person does, and read the box's value before and after leaving it: 6, then 4.

What the schema says about min and max. Microsoft's Adaptive Cards schema describes both as hints: Hint of maximum value (may be ignored by some clients). So a host decides what to do with them.

What the input validation guide says. Microsoft's Input Validation page lists min and max as the validation properties of Input.Number, and then explains exactly this: Min and max properties (including maxLength) on some platforms may be enforced directly by the control. For example, a min property on Input.Date may be enforced by not allowing users to select a date before the minimum in a date picker. In that case, the error message may not be shown.

Why It Happens​

Teams' number box enforces min and max itself: it moves any number outside the range to the nearest limit as soon as you leave the box. So the number is never out of range when the card checks its inputs, and errorMessage has nothing to report. That's what the guide allows for.

The Fix​

There's no setting that makes Teams show the message instead. Design for what it does:

  1. Say the range in the label, as Tickets (1 to 4) does, so a number that changes on its own isn't a surprise.
  2. Keep errorMessage for the cases a host does report: other clients may not enforce min and max in the box, and Teams does show the error message of a required input left empty, as it did for a required drop-down list in my tests.
  3. Check the number in your agent before you use it. The card's checks are a convenience for the person; the agent is the one that has to be right, whatever client sent the value. Card values arrive as text, so parse them first:
C#
// tickets is the card's "tickets" value, as text.
if (!int.TryParse(tickets, out int count) || count < 1 || count > 4)
{
// Tell the person the range, and don't place the order.
}

After the Fix​

The card says its range up front, Teams keeps every value inside it, and the agent's own check covers any client that doesn't. In Teams, the agent received 4 for a typed 6, as shown above: the number the person could see in the box before selecting Buy.

Common Mistakes​

MistakeWhat happensDo this instead
Relying on errorMessage to tell people the rangeIn Teams, it never shows for min or maxPut the range in the label
Trusting the number because the card has maxOther clients may not enforce itCheck it in the agent
Treating the value as a numberIt arrives as text, "4"Parse it with int.TryParse

Troubleshooting​

SymptomLikely causeFix
A number changes when you leave the boxTeams enforces min and max in the boxExpected: show the range in the label
The card sends a different number than was typedThe box moved it to the nearest limitExpected: the box shows the number that will be sent
errorMessage never appearsNothing is out of range by the time the card checksUse it with isRequired, and check in the agent

FAQ​

Does this happen with Input.Text maxLength too?​

The guide names maxLength among the properties a control may enforce. In Teams, a multi-line text box with maxLength of 300 stopped taking characters at 300, so its error message had nothing to report either.

Will other apps show the error message?​

Possibly: the guide says enforcement happens on some platforms. That's one more reason to keep the message, and to check in the agent.

Conclusion​

In Teams, an Adaptive Card number box with min and max moves numbers into the range itself, so its errorMessage doesn't appear for them. Microsoft's input validation guide expects this. Put the range in the label, keep the error message for other cases and clients, and let the agent check every number it receives.

Additional Resources​