sql_query
Run read-only SELECT or WITH queries over approved health views to compare markers, apply custom date filters, or aggregate data when dedicated tools don't fit. Returns up to 200 rows.
Instructions
Run a custom read-only SQL query (one SELECT or WITH … SELECT) over the
approved views when no other tool answers the question — e.g. comparing several markers, custom
date filters or aggregates. Runs as a view-only database role in a read-only transaction with a
5 s timeout; returns at most 200 rows (truncated tells you if there were more). Base tables,
pending values and writes are not accessible. Prefer the dedicated tools (query_observations,
get_trend, query_food…) when they fit.
Only READ-ONLY views are available (approved + not deleted): v_observations(id, user_id, type_code, name_uk, category, specimen, effective_at, value_numeric, comparator, value_text, unit, value_canonical, canonical_unit, ref_min, ref_max, status, result_status, context, panel_id) v_observations_pending(... , review_status, review_note) -- NOT fact, only for review v_medications_current(id, medication_name, dose_amount, dose_unit, times_per_day, ...) v_diagnoses(id, diagnosed_at, diagnosis_name, icd10_code, clinical_status, verification_status) v_allergies(id, allergen, reaction, severity, verified) -- verified=false is ALSO an allergy v_food_log(id, user_id, eaten_at, meal_type, description, portion, nutrient_source, glycemic_index, glycemic_load, symptoms, wellbeing, notes) v_food_nutrients(food_log_id, user_id, eaten_at, meal_type, nutrient_code, name_uk, category, unit, amount, rda, upper_limit) -- nutrients per meal v_meal_templates(id, user_id, name, meal_type, description, nutrients, glycemic_index) health_timeline(kind, user_id, id, at, title) Examples: SELECT type_code, effective_at, value_canonical FROM v_observations WHERE type_code='cholesterol_total' ORDER BY effective_at DESC; SELECT * FROM v_diagnoses WHERE verification_status='confirmed';
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |