faostat_count_data
Count the rows a FAOSTAT query would return before fetching them, using the same filters and null-value settings, to size a dataset or verify filter codes without downloading data.
Instructions
Count the rows of a FAOSTAT query before fetching them, filtered as get_data filters.
One get_data request with no_records=true, which FAOSTAT answers with the query's number of rows: data is that whole number, as is meta.total. It takes get_data's filters and null_values, which decide the rows, and refuses before any request where get_data does. The structure is read first, kept for a day, since a count prints no column to prove a filter's dimension; a filter of several codes is checked against its list before the count, and a count of 0 has each filter's list read: a wrong code, year or dimension raises InvalidRequestError naming the closest, else meta.names names each code. meta.vintage is the domain's last update. A call sends at most twelve requests (structure, code lists, count, release date), each tried up to four times, 48 requests at most, a login where the process holds no token, and a login and the request again where FAOSTAT refuses with 401 or 403.
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": {
"domain_code": "<domain_code>"
},
"name": "faostat_count_data"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| area | No | One area code or several, FAO's, as ``list_codes(domain_code, "area")`` lists them, e.g. ``"231"`` (United States of America) or ``["231", "79"]``. | |
| item | No | One item code or several, as ``list_codes(domain_code, "item")`` lists them, e.g. ``"15"`` (Wheat). | |
| year | No | One year or several, each one that ``list_codes(domain_code, "year")`` lists, e.g. ``2020`` or ``[2015, 2016, 2017]``. | |
| element | No | One element code or several, the filter codes that ``list_codes(domain_code, "element")`` lists, e.g. ``"2510"`` (Production Quantity in QCL); ``5510``, the code its rows print, is refused naming ``2510``. | |
| filters | No | Any other dimension's codes by its id, as ``get_data`` takes them, e.g. ``{"month": "7001"}`` for PP; an id that the dataset's structure lacks is refused before the count, and one that ``get_data`` sends itself (``area``, ``page_size``, ``no_records``) before sending. | |
| domain_code | Yes | The domain's code, as ``list_domains`` lists it, e.g. ``"QCL"`` (Crops and livestock products) or ``"FS"`` (Suite of Food Security Indicators); one FAOSTAT does not have raises ``NotFoundError``, and an empty text, ``"."`` or ``".."`` is refused before sending. | |
| null_values | No | ``True`` counts the rows of which FAOSTAT holds nothing too, as ``get_data`` with ``null_values=True`` returns them; ``False``, the default, leaves them out. |