# `find`: pick the one line that best answers a question.

*find prints the line with the 30 day refund deadline.*

```
question="Which line gives the refund deadline?"

cat <<'EOF' |
Returns need the original receipt.
Refunds are issued within 30 days of purchase.
Shipping is free on orders over $50.
Gift cards cannot be exchanged for cash.
EOF
thinkthen find "$question"
```

*Output*

```
Refunds are issued within 30 days of purchase.
```

*exit 0: a line came back*

You give it a question and 2 to 255 lines or records, or 2 to 254 with --none. You get back the one line that fits best.

## Read the answer

Without --none, find must pick a line. When nothing fits, the line it picks is wrong. --none lets it say nothing fits.

| Exit code | What it means |
| --- | --- |
| 0 | a line came back |
| 3 | nothing fits, under --none |
| 2 | usage or input error |
| 4 | the backend failed or refused, as it does for evidence over the size limit |
| 5 | a local failure |
| 70 | a defect in the tool |

## Call it from your language

The Bash example opens this page.

```
import thinkthen as tt

question = "Which line gives the refund deadline?"
policy = [
    "Returns need the original receipt.",
    "Refunds are issued within 30 days of purchase.",
    "Shipping is free on orders over $50.",
    "Gift cards cannot be exchanged for cash.",
]
refund_deadline = tt.find(question, policy).value
assert refund_deadline["unit"] == policy[1]
```

No Polars sample for `find`.

No pandas sample for `find`.

```
import assert from "node:assert/strict";
import * as tt from "thinkthen";

const question = "Which line gives the refund deadline?";
const policy = [
  "Returns need the original receipt.",
  "Refunds are issued within 30 days of purchase.",
  "Shipping is free on orders over $50.",
  "Gift cards cannot be exchanged for cash.",
];
const refundDeadline = (await tt.find(
  question, policy,
)).value;
assert.equal(refundDeadline?.unit, policy[1]);
```

No Ruby sample for `find`.

```
library(thinkthen)

question <- "Which line gives the refund deadline?"
policy <- c(
  "Returns need the original receipt.",
  "Refunds are issued within 30 days of purchase.",
  "Shipping is free on orders over $50.",
  "Gift cards cannot be exchanged for cash."
)
refund_deadline <- tt_find(question, policy)$value
stopifnot(identical(refund_deadline$unit, policy[2]))
```

```
use thinkthen::{Engine, Question};

let tt = Engine::from_env()?;
let question = "Which line gives the refund deadline?";
let deadline = Question::find(question)?;
let policy = [
    "Returns need the original receipt.",
    "Refunds are issued within 30 days of purchase.",
    "Shipping is free on orders over $50.",
    "Gift cards cannot be exchanged for cash.",
];
let refund_deadline = tt.find(&deadline, policy)?
    .into_value();
assert_eq!(refund_deadline.selected(), Some(&policy[1]));
```

Put this code inside `fn main() -> Result<(), Box<dyn std::error::Error>>` and end it with `Ok(())`. `main` returns a `Result`, so `?` compiles.

```
#include <assert.h>
#include <json-c/json.h>
#include <thinkthen.h>

thinkthen_engine *tt = thinkthen_engine_new();
assert(tt);

const char *find =
    "{\"find\": \"Which line gives the refund deadline?\", "
    "\"units\": ["
    "\"Returns need the original receipt.\", "
    "\"Refunds are issued within 30 days of purchase.\", "
    "\"Shipping is free on orders over $50.\", "
    "\"Gift cards cannot be exchanged for cash.\"]}";
const char *expected =
    "\"Refunds are issued within 30 days of purchase.\"";
char *deadline_call = thinkthen_call(tt, find);
assert(deadline_call);
enum json_tokener_error parse_error;
struct json_object *result =
    json_tokener_parse_verbose(deadline_call, &parse_error);
assert(parse_error == json_tokener_success);
assert(result && json_object_get_type(result)
    == json_type_object);
struct json_object *value;
json_bool has_value = json_object_object_get_ex(
    result, "value", &value);
assert(has_value);
struct json_object *facts;
json_bool has_facts = json_object_object_get_ex(
    result, "facts", &facts);
assert(has_facts);
assert(facts && json_object_get_type(facts)
    == json_type_object);
struct json_object *wanted =
    json_tokener_parse_verbose(expected, &parse_error);
assert(parse_error == json_tokener_success);
struct json_object *unit;
json_bool has_unit = json_object_object_get_ex(
    value, "unit", &unit);
assert(has_unit);
assert(json_object_equal(unit, wanted));
if (wanted) json_object_put(wanted);
json_object_put(result);
thinkthen_free_string(deadline_call);
thinkthen_engine_free(tt);
```

Keep the `#include` lines on top. Put the rest inside `int main(void)` and end it with `return 0;`.

No C++ sample for `find`.

No Objective-C sample for `find`.

No COBOL sample for `find`.

No Ada sample for `find`.

No Java sample for `find`.

No Kotlin sample for `find`.

No Scala sample for `find`.

No C# sample for `find`.

No Go sample for `find`.

No Swift sample for `find`.

No Zig sample for `find`.

No PHP sample for `find`.

No Dart sample for `find`.

No DuckDB sample for `find`.

```
.load ./thinkthen

WITH picked AS (
    SELECT thinkthen_find(
        'Which line gives the refund deadline?',
        json_array(
            'Returns need the original receipt.',
            'Refunds are issued within 30 days ' ||
            'of purchase.',
            'Shipping is free on orders over $50.',
            'Gift cards cannot be exchanged for cash.'
        )
    ) AS deadline_result
)
SELECT json_extract(deadline_result, '$.value')
    AS refund_deadline
FROM picked;
```

*What SQLite printed*

```
Refunds are issued within 30 days of purchase.
```

```
WITH picked AS (
    SELECT thinkthen_find(
        'Which line gives the refund deadline?',
        ARRAY[
            'Returns need the original receipt.',
            'Refunds are issued within 30 days ' ||
            'of purchase.',
            'Shipping is free on orders over $50.',
            'Gift cards cannot be exchanged for cash.'
        ]
    ) AS deadline_result
)
SELECT deadline_result ->> 'value' AS refund_deadline
FROM picked;
```

*What PostgreSQL printed*

```
                refund_deadline                 
------------------------------------------------
 Refunds are issued within 30 days of purchase.
(1 row)
```

[Arguments, options, and more examples](/reference/functions/find/)

## Jobs that use `find`

- [Group alerts into incidents](/how-tos/group-alerts-into-incidents/): for on-call engineers

- [Check an expense against the policy](/how-tos/check-an-expense-against-the-policy/): for finance staff

Watch `find` answer questions about Beatles songs: [find picks one from many.](/learn/beatles-bench/find/)

On GitHub: [github.com/botassembly/thinkthen](https://github.com/botassembly/thinkthen)
