vxcontrol/pentagi · warning

Prompts.InvalidRequest

Prompts.InvalidRequest

Error message

group field not found

What it means

GetPrompts lists prompts and supports grouping via the `group` query parameter. The value must exist in `promptsSQLMappers`, the allowlist of fields permitted for GROUP BY (prevents SQL injection and invalid columns). An unmapped value causes this Prompts.InvalidRequest error.

Source

Thrown at backend/pkg/server/services/prompts.go:90

	privs := c.GetStringSlice("prm")
	if !slices.Contains(privs, "settings.prompts.view") {
		logger.FromContext(c).Errorf("error filtering user role permissions: permission not found")
		response.Error(c, response.ErrNotPermitted, nil)
		return
	}

	uid := c.GetUint64("uid")
	scope := func(db *gorm.DB) *gorm.DB {
		return db.Where("user_id = ?", uid)
	}

	query.Init("prompts", promptsSQLMappers)

	if query.Group != "" {
		if _, ok := promptsSQLMappers[query.Group]; !ok {
			logger.FromContext(c).Errorf("error finding prompts grouped: group field not found")
			response.Error(c, response.ErrPromptsInvalidRequest, errors.New("group field not found"))
			return
		}

		var respGrouped promptsGrouped
		if respGrouped.Total, err = query.QueryGrouped(s.db, &respGrouped.Grouped, scope); err != nil {
			logger.FromContext(c).WithError(err).Errorf("error finding prompts grouped")
			response.Error(c, response.ErrInternal, err)
			return
		}

		response.Success(c, http.StatusOK, respGrouped)
		return
	}

	if resp.Total, err = query.Query(s.db, &resp.Prompts, scope); err != nil {
		logger.FromContext(c).WithError(err).Errorf("error finding prompts")
		response.Error(c, response.ErrInternal, err)
		return

View on GitHub (pinned to ea665308ba)

Solutions

  1. Use a group value exactly matching a key in `promptsSQLMappers` in backend/pkg/server/services/prompts.go
  2. Drop the `group` query parameter to get the ungrouped list
  3. To group by a new field, register it in `promptsSQLMappers`

Example fix

// before
GET /api/v1/prompts?group=prompttext
// after
GET /api/v1/prompts?group=prompt_text
Defensive patterns

Strategy: validation

Validate before calling

const allowed = new Set(['name','type','created_at']); // mirror promptsSQLMappers keys
if (group && !allowed.has(group)) throw new Error(`invalid group field: ${group}`);

Type guard

function isValidPromptsGroup(v: string, allowed: readonly string[]): v is typeof allowed[number] {
  return (allowed as readonly string[]).includes(v);
}

Try / catch

try {
  const res = await api.get('/prompts', { params: group ? { group } : {} });
} catch (e) {
  if (e.response?.data?.code === 'Prompts.InvalidRequest') {
    // fall back to ungrouped listing
  }
}

Prevention

When it happens

Trigger: GET prompts endpoint with `group=<name>` where `<name>` is not a key in `promptsSQLMappers` — e.g. a typo, an internal column name, or a field not registered for grouping.

Common situations: Frontend dropdown out of sync with backend mapper; user hand-crafts the API call; a renamed field after a backend update still sent by an older client.

Related errors


AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01). Data as JSON: /api/errors/f82242aa0856cb3a. Report an issue: GitHub.