Mintplex-Labs/anything-llm · error

Must be a boolean

Error message

Must be a boolean

What it means

POST /api/mobile/update/:id accepts exactly one writable field, approved, and server/models/mobileDevice.js validates it with typeof value !== 'boolean'. If the body's approved is a string ('true'), number (1), or null, update returns { error: 'Must be a boolean' } which the endpoint relays as HTTP 400. Only literal JSON booleans pass.

Source

Thrown at server/endpoints/mobile/index.js:51

  );

  /**
   * Updates the device status via an updates object.
   * @param {import("express").Request} request
   * @param {import("express").Response} response
   */
  app.post(
    "/mobile/update/:id",
    [validatedRequest, flexUserRoleValid([ROLES.admin])],
    async (request, response) => {
      try {
        const body = reqBody(request);
        const updates = await MobileDevice.update(
          Number(request.params.id),
          body
        );
        if (updates.error)
          return response.status(400).json({ error: updates.error });
        return response.status(200).json({ updates });
      } catch (e) {
        console.error(e);
        response.sendStatus(500).end();
      }
    }
  );

  /**
   * Deletes a device from the database.
   * @param {import("express").Request} request
   * @param {import("express").Response} response
   */
  app.delete(
    "/mobile/:id",
    [validatedRequest, flexUserRoleValid([ROLES.admin])],
    async (request, response) => {
      try {

View on GitHub (pinned to 3aec848f28)

Solutions

  1. Send a real JSON boolean with Content-Type: application/json: {"approved":true}
  2. Convert form/DOM values explicitly before sending: approved: checkbox.checked
  3. In curl, do not quote the boolean: -d '{"approved":true}' not '{"approved":"true"}'

Example fix

// before
fetch('/api/mobile/update/3', {
  method: 'POST',
  body: JSON.stringify({ approved: 'true' }),
});

// after
fetch('/api/mobile/update/3', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ approved: true }),
});
Defensive patterns

Strategy: type-guard

Validate before calling

const payload = { approved: typeof rawValue === 'string' ? rawValue === 'true' : Boolean(rawValue) };

Type guard

/** @param {unknown} v */
function isBooleanUpdate(v) {
  return v !== null && typeof v.approved === 'boolean';
}

Prevention

When it happens

Trigger: Sending {"approved":"true"} (string), {"approved":1}, or a form-urlencoded body where Express parses the value as a string; sending approved:null to try to 'clear' the field.

Common situations: HTML forms or FormData serializing booleans as strings; clients whose types allow boolean|string; curl commands with the value quoted; query-string style bodies.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/d02c9b3afd9bc513. Report an issue: GitHub.