scrapewise_preview_scraper_preview_rule
Applies a single PostProcessRule to a user-provided sample value and returns the
derived output without persisting anything or running a real scrape. Useful for
validating a rule's parameters before saving it onto a scraper config. For
CURRENCY_CONVERT rules, also returns the FX rate and rateDate used. One rule, one value:
conditions and choice groups are not checked here.
Rule kinds and params:
- CURRENCY_CONVERT: params {from, to} (3-letter codes). Writes outputField (value not
rounded) plus ONE shared pair per target currency per row: <to>_rate and
<to>_rate_date (to lower-cased, e.g. eur_rate, eur_rate_date; ECB rate and date).
Every CURRENCY_CONVERT rule with the same `to` shares the pair; all rules of one run
use one rate table. An identity in-place rule (overwritesRawField=true and from = to)
only cleans the number and writes no pair. Row markers: RULE_RATE_CONFLICT:<to>_rate
when two rules on one row need two different rates (both values kept, no pair);
RULE_UNUSABLE:<to>_rate when the row already had its own <to>_rate / <to>_rate_date
(kept untouched) and the computed one differs.
- ENUM_MAP: params {mapping: {rawValue: mappedValue}, default}. mapping must be
non-empty, or empty ({}) with a default: then default is a fixed value written on
every row.
- REGEX_CLEAN: params {keep: "[A-Za-z0-9]"} (a simple character class).
- QUANTITY_NORMALIZE ("price per unit"): params {quantityField OR quantityValue,
targetQuantity}. output = row[sourceField] / divisor * targetQuantity, rounded
half-up to 4 decimals (price 7.5, pack 100, target 50 -> 3.75). Divisor = exactly
one of: quantityField (a scraped field such as pack_grams, or the output of an
earlier NUMBER_EXTRACT / QUANTITY_NORMALIZE rule) or quantityValue (a fixed number
> 0 and <= 1000000; e.g. minor units 2500 -> 25.00 with quantityValue 100,
targetQuantity 1; kg -> g with quantityValue 1, targetQuantity 1000).
targetQuantity is a number > 0 and <= 1000000. When the source or quantity is
missing, not an unambiguous number ("1.000" is refused), zero/negative, the result
is out of range or rounds to 0, the rule writes NO column for that row (never 0 or
null) and this preview returns `skipped` with the reason. Cannot be combined with
overwritesRawField=true.
- NUMBER_EXTRACT ("take a number from text"): params {units}. Reads the number
written right BEFORE one of the unit words in a text column, times that unit's
factor; NUMBER output, 4 decimals. units = a preset name (WEIGHT_G, VOLUME_ML,
PIECES — see scrapewise_get_scraper_config_parameters postProcessUnitPresets) or a
list of 1-20 {token, factor} (factor default 1). The unit listed first wins:
"0.66 lb 300 g" with WEIGHT_G -> 300; "100m/50g" with [{token:"g"}] -> 50;
"3.53 oz" with WEIGHT_G -> 100.0738. Never guesses: multipacks ("3x100g"),
grouped numbers ("1 500 g"), ranges ("50-100 g"), ambiguous numbers ("1.000 g"),
zero or no match -> skipped. Reads the first 2,000 characters.
Ordered chaining (on a saved scraper): rules run top to bottom once. The output of an
EARLIER QUANTITY_NORMALIZE or NUMBER_EXTRACT rule may be read by a later
CURRENCY_CONVERT or QUANTITY_NORMALIZE rule as sourceField, and by a later
QUANTITY_NORMALIZE as quantityField. Example: rule 1 QUANTITY_NORMALIZE
price/pack_grams*50 -> price_per_50g, rule 2 CURRENCY_CONVERT price_per_50g DKK->EUR
-> price_per_50g_eur. Outputs of CURRENCY_CONVERT, ENUM_MAP and REGEX_CLEAN cannot be
read; ENUM_MAP, REGEX_CLEAN and NUMBER_EXTRACT read scraped fields only. Rejected at
save (400): reading a later rule's output or a shared <to>_rate / <to>_rate_date
column, or a later rule writing a column an earlier rule reads.
Args:
- body (PostProcessRulePreviewRequest, required):
- rule (PostProcessRule): the rule definition (kind, sourceField,
outputField, outputType, params).
- sampleValue (any): the input value to apply the rule to.
- sampleQuantity (any, optional): QUANTITY_NORMALIZE with quantityField only —
the pack size to divide by (placed on the sample row under the rule's
quantityField). Omit it to see how the rule behaves when the quantity is
missing. Ignored when the rule uses quantityValue.
Returns:
PostProcessRulePreviewResponse with output (the derived value), and for
CURRENCY_CONVERT rules: rate + rateDate. `skipped` (text) when the rule ran but
could produce no value for this sample (QUANTITY_NORMALIZE). On invalid rule
params or unhandled error, returns an `error` field instead of `output`.
Examples:
- Use when: "what would REGEX_CLEAN do to '$1,234.56'?" → preview with that rule
- Use when: "price per 50 g for a 100 g ball at 7.50?" → QUANTITY_NORMALIZE with
sampleValue 7.5, sampleQuantity 100, params {quantityField: "pack_grams",
targetQuantity: 50} → output 3.75
- Use when: "what pack size is in 'Hygge Wool 100 g'?" → NUMBER_EXTRACT with
sampleValue "Hygge Wool 100 g", params {units: "WEIGHT_G"} → output 100
- Don't use when: you want the rule applied to actual scraped data → save the
rule on the scraper config and run a fresh scrape
Error Handling:
- 400 if request body validation fails.
- 200 with `error` field for rule-execution failures (intentional non-throw
shape so the agent can iterate on rule params without exception handling).
- 401 Unauthorized.[runtime hint] This tool returns JSON-as-text — its response shape is dynamic (per-scraper itemsConfig, file binary, etc.) so the MCP outputSchema is omitted. Do not rely on the presence of any specific field in the response; treat the result as a string-or-object blob and parse defensively.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"body": "<body>"
},
"name": "scrapewise_preview_scraper_preview_rule"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| body | Yes |