Skip to main content

Parse user input

Version: V2
View Markdown

Turn a pasted URL, IID, or text label into a local candidate that your application can inspect before classification.

Prompt for your agentTurn pasted input into a reviewable candidate
Goal: add a local parser that turns whatever a user pastes into a candidate my app can review.
Read https://docs.intuition.systems/docs/build/parse-input.md, https://docs.intuition.systems/docs/concepts/atom-parsing.md and https://docs.intuition.systems/docs/reference/packages/atom-parser.md.
Use exact package versions from https://docs.intuition.systems/intuition-release.json and public entry points only.
Input: a pasted URL, IID or plain text label. Enforce a byte limit at the input boundary and pass the parser limit explicitly.
Output: the result kind, the candidate and every warning, unchanged. Return structured errors for invalid identifiers and oversized input instead of throwing.
Keep parsing local: pass remoteFetch: false, and do not fetch the URL or call any provider.
Add tests for a valid URL, a valid IID, a malformed IID, a plain label and an oversized input.
Report the checks you actually ran and anything you could not verify.

Paste this into your coding agent. It points the agent at the Markdown version of each page and leaves every signature to you.

Before you start​

Choose how many input bytes your host can accept and apply that limit at the transport boundary. This example also sets a 64-byte parser limit to make the oversized case easy to try. See atom parsing.

For your own project, follow Install the packages. To run the offline example, install its locked dependencies from the documentation repository root with Node.js 22.21.0.

npm ci --prefix examples/v2 --ignore-scripts

Steps​

1. Make local parsing explicit​

Pass remoteFetch: false for pasted input. The package default allows remote inspection for eligible URLs and IPFS inputs. With inspection disabled, URL detection only interprets the supplied text. The parser trims outer ASCII whitespace for detection and measures the original input in UTF-8 bytes for the size limit.

2. Use the result kind and preserve warnings​

For a URL, take canonicalUrl. For an IID, check valid before using canonicalIid and keep the reason when validation fails. A plain_string is a label you can offer for classification or manual entry. The helper preserves the parser’s warnings for all returned candidates and handles ParseError codes separately.

import { parseAtom, ParseError } from '@0xintuition/atom-parser';

export async function parseCandidate(input: string) {
try {
const result = await parseAtom(input, {
remoteFetch: false,
maxInputBytes: 64,
});
const { kind, warnings } = result;
if (result.kind === 'iid') {
return {
kind,
warnings,
valid: result.valid,
iid: result.canonicalIid,
anchorEligible: result.anchorEligible,
reason: result.reason,
};
}
return {
kind,
warnings,
value:
result.kind === 'url' ? result.canonicalUrl : result.normalizedInput,
};
} catch (error) {
if (!(error instanceof ParseError)) throw error;
return { error: error.code };
}
}

3. Decide what to retain​

Present a canonical identifier to the caller for review. Keep free text available for correction or classification. Even a syntactically valid identifier still requires evidence that it belongs to the intended entity.

Check the result​

node examples/v2/music-catalog/src/parse-input.ts
InputExpected result
https://example.org/catalogurl with canonical URL https://example.org/catalog
INT:ISRC:US-RC1-76-07839iid, valid, with int:isrc:USRC17607839
int:unknown:exampleiid, invalid, with reason unknown_or_malformed_iid
A catalog labelplain_string
Spaces onlyEMPTY_INPUT
65 ASCII charactersINPUT_TOO_LARGE

All four returned candidates in this run have an empty warnings list, including the invalid IID. Use the IID’s valid field for the decision.

Atom parser package, detection order, remote inspection and byte checks, and IID result fields.

Applies to V2 · @0xintuition/atom-parser 0.1.1