Render a graded coding exercise
render_exerciseRender a graded coding exercise as an interactive widget. Learners use the editor and Submit to run hidden tests, and failed attempts are returned to the chat for targeted feedback.
Instructions
Render a graded coding exercise as an interactive widget in the conversation.
The learner gets a lesson pane and an editor pane with Run and Submit. Submit executes your hidden tests against their code in the browser and shows a pass/fail verdict. On failure they can push their exact code and the exact error back into this conversation with one click — that is the point of this tool, so write tests whose failures are informative.
Call this when someone asks to learn, practise or be quizzed on Python, JavaScript, TypeScript or SQL. Author everything yourself: there is no curriculum behind this tool.
Rules for good exercises:
One concept, one answer, solvable in a few minutes.
'task_md' must state exactly what is wanted: the function and signature the tests call, or for SQL which columns come back and whether row order matters.
'starter_code' contains the skeleton and a placeholder, never the answer.
'tests' are hidden until submission, and their form differs by language — see the field description. Test only what 'task_md' actually asked for; a test the learner could not have anticipated is a bug, not a difficulty.
SQL exercises also need 'seed'. The learner sees the schema, not your reference query.
Hints escalate: first a nudge, last one close to the answer.
When the learner is stuck or posts a failed attempt back into the chat, explain what THEIR code did wrong and point at the next hint. Do not hand over the solution on request; that is what the gated "show solution" button in the widget is for. If they insist after several genuine attempts, walk them through it rather than pasting it.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| seed | No | SQL only, and required for sql: CREATE TABLE statements plus INSERTs, run before anything else on a fresh in-memory database. Keep it small — a handful of rows chosen so a wrong query gives a visibly wrong answer, including at least one edge case (a NULL, a tie, an empty group). The widget shows the learner the resulting table names, columns and row counts, so this is not hidden; the reference answer in 'tests' is. | |
| hints | No | Escalating hints, nudge first and near-answer last. Revealed one at a time: the first is free, each later one unlocks after another failed submission. | |
| tests | Yes | The hidden grader, never shown before submission. Its form depends on the language. python: plain `assert` statements, at least three, one an edge case. javascript/typescript: `assert(cond, msg)`, `assertEquals(actual, expected)` and `assertDeepEquals(actual, expected)` are in scope; at least three assertions. Tests run in the same scope as the learner's code, so they can call whatever it defines. TypeScript tests may be typed; the types are erased before running. sql: a *reference answer written as SQL* — not expected rows. It runs against its own copy of the seeded database and the learner's result set is compared to it, so write the query you would accept as correct. Row order is enforced only if the reference has an ORDER BY; force it either way with a first line of `-- ordered` or `-- unordered`. For an INSERT/UPDATE/DELETE exercise, write the equivalent statements and the resulting table contents are compared instead. | |
| title | Yes | Short exercise title, e.g. 'f-strings: formatting numbers'. | |
| task_md | Yes | Markdown. Exactly what the learner must produce. For python/javascript/typescript, name the required function and its signature. For sql, say which columns to return, in what order, and whether row order matters. | |
| language | Yes | Runtime for the exercise. 'python' runs on Pyodide; 'javascript' and 'typescript' in a sandboxed worker; 'sql' on SQLite. All four execute in the learner's browser. | |
| solution | No | Reference solution. Kept hidden by the widget until three failed submissions. | |
| lesson_md | Yes | Markdown. The concept plus one worked example. Keep it short — a screenful, not a chapter. | |
| starter_code | Yes | What the editor opens with. Include the signature and a '# your code here' placeholder, never the answer. For sql, a comment and the skeleton of a statement (e.g. 'SELECT ... FROM orders'). |