All guides

Trace input validation paths in your code with Cursor

Use Cursor's exact-match search and Explore subagent to locate where user input is validated, check each hit by hand, and record the result before stopping.

AINavWritten / Updated Sources checked
On this page

At a glance

When you inherit an unfamiliar project, a common question is where user input is actually validated. Cursor's official documentation describes two search abilities of Agent. Instant Grep handles exact matches such as function names, variables, error strings or regex patterns. The Explore subagent runs broad parallel searches in its own context and returns only relevant findings. This guide chains them into one task: find where one kind of input is validated in your own project and turn the findings into a checklist you can verify. It is based on reading the documentation and was not run.

Workflow

  1. Exact first, broad second

    With a known symbol or error string, let Agent locate it by exact match or regex first. If clues are thin, ask the Explore subagent for a broad search.

  2. Let the subagent compress context

    Wide searches produce a lot of content. The subagent searches in its own context window and hands back only summarized findings, which keeps the main conversation focused.

  3. Confirm in the files yourself

    Search results are leads. Read the files, not the summary, to judge whether validation exists and is complete.

Each stage cites official sources.

Before you start

  • The target project folder is open in Cursor. In a multi-root workspace, the documentation says each folder's context is available to Agent, but features that need a single git root, such as worktrees, are disabled.
  • You know at least one concrete clue, such as a handler function name, an error message string or a validator name, to use as the starting point for exact search.
  • You know that the content of a file Agent opens can still be included in the model request. Read the official Data Use description before working with sensitive code.

1. Define the input to trace

In the Cursor Agent conversation, write the goal in one sentence, for example: the email and nickname submitted at sign-up. Also list the clues you already have, such as a handler function name and an error message. The more specific the clue, the better exact search works.

2. Search by exact symbol

In the chat input, reference the specific symbol or string and ask Agent to find its definition and references. The documentation says Agent uses grep automatically when you mention specific symbols, with no configuration. For pattern matching you can write a regex such as import.*PaymentService to trace references across files.

3. Ask for the Explore subagent when clues run out

If you do not know where to start, request it directly, for example: "use a subagent to find all the places we validate user input." The documentation gives this form of request, and Agent may also use the subagent on its own when it decides a task benefits from broad search.

4. Read the list and sample the files

Ask Agent to format results as file path, location and what is validated. Then pick several entries and open the original files in the editor to confirm each one validates that input and does not merely have a similar name.

5. Fill in missing paths

For any entry point absent from the list, search again with a different symbol or error string, such as another endpoint's handler. Merge new findings into the same list so a second call path is not missed.

6. Record the result and stop

When every known entry point maps to a validation location or is explicitly marked as no validation found, you are done. Save the list in your own notes and do not let Agent continue editing code. This task is reading and locating only.

Original example

Synthetic sample: a demo project called demo-shop has two entry points, one for sign-up (function handleSignup) and one for changing a nickname (function updateNickname), with the error string "nickname too long". In the Agent chat you type: "In demo-shop, find where handleSignup and updateNickname validate input, also search the string nickname too long, and list file path, location and what is checked. Read only, do not edit." You would expect a list such as: the sign-up entry calls a validator that checks email format; the nickname entry only checks for empty values and has no length check. That is illustrative, not real output. You then open those files, find the nickname entry lacks a length check, note it as needing validation, and end the task.

Completion checks

  • Every item on the list can be found in the named file, and you have read the original code.
  • All known entry points are covered, not only the first one the search hit.
  • The meaning of validation is accurate: format, length and required checks each exist.
  • Agent only read files and made no edits you did not ask for.

Limits

  • Search finds text matches. If validation uses dynamically built names or external configuration, exact search may miss it and you must investigate separately.
  • Content of opened matching files may be included in the model request, so confirm the data use description before handling sensitive code.
  • Cloud Agents do not support multi-root workspaces, and features needing a single git root are disabled in them.
  • The subagent returns a summary that may omit detail. It cannot replace reading the source or prove the validation is secure.

Verification scope

Only the official Cursor search documentation was read; login, installation, product API execution, file upload and generated output were not tested. The sample project and list are synthetic, not real run results.

Article sources

Original editorial content; official descriptions and checking suggestions are distinguished.

  1. Cursor · Official sources
    View details