PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?character ?characterLabel WHERE {
  ?character wdt:P725 wd:Q37628 .
  ?character wdt:P31 wd:Q123126876 .
  ?character rdfs:label ?characterLabel .
  FILTER ( LANG( ?characterLabel ) = "en" )
}

Using entities:
- animated television character (wd:Q123126876), also known as animated TV character: is instance of type of fictional character / is subclass of animated character / is subclass of television character / fictional character from an animated work on television
- Mila Kunis (wd:Q37628), also known as Milena Markivna Kunis, Milena Markovna: has occupation voice actor / has occupation child actor / has occupation television producer / has occupation Model / has occupation model / has occupation actor / has occupation television actor / has occupation film actor / is instance of human / American actress / American actress / Ukrainian-American actress

Using properties:
- instance of (wd:P31 as wdt), also known as example of, has type, is a, is an, is of type, etc.: that class of which this subject is a particular example and ... a subclass of mountain (and an instance of volcanic landform) / type to which this subject corresponds/belongs. Different ... and the volcano is a type (instance) of volcanic landform
- voice actor (wd:P725 as wdt), also known as dubbed by, seiyu, VA, VO, vocal role as, etc.: is subproperty of cast member / is subproperty of film crew member / performer of a spoken role in a creative work such as ... as qualifier] [use "cast member" (P161) for live acting]

Answer: Mila Kunis plays Meg Griffin on Family Guy.

Mila Kunis plays Meg Griffin on Family Guy.

SPARQL query over wikidata:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?character ?characterLabel WHERE {
  ?character wdt:P725 wd:Q37628 .
  ?character wdt:P31 wd:Q123126876 .
  ?character rdfs:label ?characterLabel .
  FILTER ( LANG( ?characterLabel ) = "en" )
}

Using entities:
- animated television character (wd:Q123126876), also known as animated TV character: is instance of type of fictional character / is subclass of animated character / is subclass of television character / fictional character from an animated work on television
- Mila Kunis (wd:Q37628), also known as Milena Markivna Kunis, Milena Markovna: has occupation voice actor / has occupation child actor / has occupation television producer / has occupation Model / has occupation model / has occupation actor / has occupation television actor / has occupation film actor / is instance of human / American actress / American actress / Ukrainian-American actress

Using properties:
- instance of (wd:P31 as wdt), also known as example of, has type, is a, is an, is of type, etc.: that class of which this subject is a particular example and ... a subclass of mountain (and an instance of volcanic landform) / type to which this subject corresponds/belongs. Different ... and the volcano is a type (instance) of volcanic landform
- voice actor (wd:P725 as wdt), also known as dubbed by, seiyu, VA, VO, vocal role as, etc.: is subproperty of cast member / is subproperty of film crew member / performer of a spoken role in a creative work such as ... as qualifier] [use "cast member" (P161) for live acting]

Execution result:
Got 1 row and 2 columns:
| character                | characterLabel        |
| ------------------------ | --------------------- |
| Meg Griffin (wd:Q908772) | Meg Griffin (lang:en) |

[System]
You are a question answering assistant. Your job is to generate a SPARQL query to answer a given user question.

You should follow a step-by-step approach to generate the SPARQL query:
1. Determine possible entities and properties implied by the user question.
2. Search for the entities and properties in the knowledge graphs. Where applicable, constrain the searches with already identified entities and properties.
3. Gradually build up the SPARQL query using the identified entities and properties. Start with simple queries and add more complexity as needed. Execute intermediate queries to get feedback and to verify your assumptions. You may need to refine or rethink your current plan based on the query results and go back to step 2 if needed, possibly multiple times.
4. Use the answer or cancel function to finalize your answer and stop the generation process.

Available knowledge graphs:
- wikidata at http://localhost:7001 with prefix index for entities and similarity index for properties, and notes:
  - P106 = occupation. Use wdt:P106 to get occupations and fetch English labels with rdfs:label + FILTER(LANG(?label)="en"). When returning human occupations confirm the subject is human (wdt:P31 wd:Q5) to avoid non-human items.
  - Population (P1082) and tabular (P4179): use wdt:P1082 for quick/direct values; for time-series/point-in-time use p:P1082 + ps:P1082 + pq:P585 and ORDER BY pq:P585 DESC. Inspect statement qualifiers (e.g., 'applies to part') and prov:wasDerivedFrom references (pr:P854 etc.) to detect city-proper vs metro/prefecture scopes before using values.
  - Common person properties: P31 (instance of human Q5), P106 (occupation), P569 (date of birth), P19 (place of birth), P27 (country of citizenship), P21 (sex/gender), P166 (award received). Use wdt: for direct values when possible.
  - P17 (country) can be incomplete/misleading for places (historical/overseas tags). To get modern cities in a country combine: instance-of city (P31=Q515) + wdt:P17 OR use wdt:P131* to find an admin parent whose wdt:P17 = the country. Also cross-check coordinates (P625) or admin hierarchy to spot outliers.
  - When filtering by date of birth (P569) use xsd:dateTime comparisons (e.g. >= "1900-01-01T00:00:00Z"^^xsd:dateTime). Be aware many items have year-only or imprecise dates and coverage is biased toward notable/public figures (sportspeople, politicians, artists).
  - To retrieve qualifiers (e.g., award year) use the statement/qualifier pattern: p:Pxxx / ps:Pxxx / pq:P585. Use wdt:Pxxx for normalized/direct values when you don't need qualifiers. Example: p:P166 + pq:P585 gives award year.
  - To get a person's occupations: use wdt:P106 for direct/normalized values and rdfs:label for human-readable names (FILTER(LANG(...))). Example: wd:Q... wdt:P106 ?occ . ?occ rdfs:label ?occLabel . FILTER(LANG(?occLabel)="en").
  - P166 = award received. Use wdt:P166 for normalized/direct values when you only need award items. To get award years or qualifiers use p:P166 / ps:P166 / pq:P585. Many statements lack pq:P585 — use OPTIONAL { ?stmt pq:P585 ?date } and ORDER BY DESC(?date). When listing award winners, filter ?person wdt:P31 wd:Q5 to ensure humans.
  - Population time-series pattern: wd:Q... p:P1082 ?stmt . ?stmt ps:P1082 ?pop . OPTIONAL { ?stmt pq:P585 ?date } . ORDER BY DESC(?date). pq:P585 is the point-in-time qualifier. IMPORTANT: time-series may mix scopes (city proper vs metro) — e.g., Tokyo has a 2016 entry ~38,140,000 likely metro vs smaller city figures. Inspect qualifiers/references for scope before use.
  - Use wdt:P131* to traverse the admin hierarchy and compare wdt:P17 on the place vs an admin parent to detect historical/colonial country assignments. When mismatches appear, inspect the admin parent's instance-of (P31), labels, qualifiers and references to interpret the historical scope.
  - wdt:P106 often yields multiple occupations for a person. Use GROUP_CONCAT(DISTINCT ?occLabel; separator=", ") or return multiple rows. Always fetch labels with rdfs:label + FILTER(LANG(?label)="en") to get readable occupation names.
  - When a search_entity returns multiple hits (person vs sculpture vs memorial), confirm you selected the human/statements by checking wdt:P31 (instance of) and relevant wdt: properties (e.g., wdt:P106). This avoids using a non-human QID by mistake.
  - search_autocomplete can be constrained with a SPARQL pattern containing ?search (e.g., SELECT * WHERE { ?search wdt:P31 wd:Q5 }). Use constraints to focus results (e.g., humans) and avoid ambiguous fallbacks; if it returns no results, fallback to search_entity and verify wdt:P31.
  - Use search_property_of_entity to find relevant properties for an entity (e.g., 'award' -> P166) and search_object_of_property to discover candidate objects (e.g., 'physicist' for P106). This reduces guessing P/Q ids and surfaces qualifiers.
  - Inspect statement references and qualifiers: use prov:wasDerivedFrom on p: statements to find sources, and check qualifiers (e.g., 'applies to part' or other scope qualifiers) to disambiguate city vs metro vs admin area. Reference labels can be empty; inspect reference node properties for URLs or publication dates.

Index types used for entities and properties:
- Prefix index: Retrieves items by overlap between query keywords and item words. The query keywords can match item words exactly or as prefixes.
- Similarity index: Retrieves items by cosine similarity between their embeddings and the query embedding.

General notes across knowledge graphs:
- Use rdfs:label + FILTER(LANG(?label)="en") for labels; avoid SERVICE wikibase:label. Use wdt:Pxxx for normalized/direct values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access statement qualifiers (e.g., award year via pq:P585). When dates matter, prefer xsd:dateTime and watch for year-only precision.
- Practical query patterns: use rdfs:label + FILTER(LANG(...)) for labels. Use wdt:Pxxx for direct/normalized values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access qualifiers (dates via pq:P585). For dates use xsd:dateTime and expect year-only precision. For places: combine P17 with P131 or coordinate (P625) filters to avoid historical/overseas mismatches.
- Use OPTIONAL for pq: qualifiers (e.g., pq:P585), sort by qualifier (ORDER BY pq:P585 DESC) to prefer recent values. Use GROUP_CONCAT to combine multiple labels/values in one row. Watch for typed literals (xsd:dateTime, xsd:decimal) when filtering or sorting.
- Before querying, use search_entity to resolve human-friendly names to wd:Q identifiers and verify instance-of (e.g., check wdt:P31 = wd:Q5 for humans) to avoid ambiguous matches. Prefer the top match but programmatically confirm P31 before using its data.
- Use search_property to confirm property identifiers (e.g., "country" -> P17) before embedding them in queries. This prevents mistakes from assuming an ID and helps pick the best property if multiple choices exist.
- search_autocomplete can fall back to an unconstrained search or error when there are too many candidates. If this happens (e.g., "more than the maximum supported number of subject candidates"), retry with narrower constraints such as instance-of (wdt:P31), additional type filters, or short prefixes to reduce the candidate set; otherwise fallback to search_entity and verify wdt:P31.
- Use list(...) to inspect all triples on an entity for exploration, but expect large results for notable items. Prefer wdt: properties or targeted p:/ps:/pq: patterns in SPARQL when you need normalized values or qualifiers, respectively.
- Before embedding property or item IDs in SPARQL, use search_property, search_property_of_entity, and search_object_of_property to discover the appropriate P/PID or object QIDs. This reduces errors from guessing IDs and surfaces better property alternatives and qualifiers.
- search_constrained and search_autocomplete can return no results for constrained queries or when the index is large. If they fail, fallback to search_entity + verify P31 (or use search_property_of_entity). Constrain with instance-of (wdt:P31) or other properties in the SPARQL to improve matches.
- When selecting awards by year, prefer xsd:dateTime range filters (e.g., >= "2001-01-01T00:00:00Z"^^xsd:dateTime && < "2002-01-01T00:00:00Z"^^xsd:dateTime) instead of YEAR() for portability and precision.
- When selecting award winners via wdt:P166, filter ?person wdt:P31 wd:Q5 to ensure humans — fictional characters or non-humans may have award claims. If you need award years use p:P166 / ps:P166 / pq:P585 and OPTIONAL { ?stmt pq:P585 ?year } to retrieve qualifier years.
- Use wdt:P625 (coordinates) together with wdt:P131* and wdt:P17 checks to validate a place's modern country or to filter by geography. When country labels mismatch historically, inspect admin parents and coordinates to resolve whether the item refers to historical/colonial scope or current boundaries.
- Prefer wdt:Pxxx for normalized/direct values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access qualifiers (e.g., pq:P585 for award year). Always fetch labels with rdfs:label + FILTER(LANG(?label) = "en").
- If search_autocomplete returns too many candidates or errors, retry with constraints (e.g., SELECT * WHERE { ?search wdt:P31 wd:Q5 }) or narrower query text. If still failing, fallback to search_entity and verify wdt:P31 for type checks.
- For award-year queries use p:P166 / ps:P166 / pq:P585 to access award statements and year qualifiers. Filter by xsd:dateTime ranges (e.g., >= "2020-01-01T00:00:00Z"^^xsd:dateTime && < "2021-01-01T00:00:00Z"^^xsd:dateTime) instead of YEAR() for robustness.
- Use search_property_of_entity to surface relevant properties for an entity (e.g., 'birth' -> P569/P19). list(...) can inspect triples but may return large results for notable items—prefer targeted wdt: patterns (wdt:Pxxx) or p:/ps:/pq: patterns when you need qualifiers.

SPARQL prefixes for use in function calls:
- bd: <http://www.bigdata.com/rdf#
- cc: <http://creativecommons.org/ns#
- data: <https://www.wikidata.org/wiki/Special:EntityData/
- dc: <http://purl.org/dc/elements/1.1/
- dct: <http://purl.org/dc/terms/
- foaf: <http://xmlns.com/foaf/0.1/
- geo: <http://www.opengis.net/ont/geosparql#
- geof: <http://www.opengis.net/def/function/geosparql/
- gn: <http://www.geonames.org/ontology#
- hint: <http://www.bigdata.com/queryHints#
- imdb: <https://www.imdb.com/
- math: <http://www.w3.org/2005/xpath-functions/math#
- ontolex: <http://www.w3.org/ns/lemon/ontolex#
- owl: <http://www.w3.org/2002/07/owl#
- p: <http://www.wikidata.org/prop/
- pq: <http://www.wikidata.org/prop/qualifier/
- pqn: <http://www.wikidata.org/prop/qualifier/value-normalized/
- pqv: <http://www.wikidata.org/prop/qualifier/value/
- pr: <http://www.wikidata.org/prop/reference/
- prn: <http://www.wikidata.org/prop/reference/value-normalized/
- prov: <http://www.w3.org/ns/prov#
- prv: <http://www.wikidata.org/prop/reference/value/
- ps: <http://www.wikidata.org/prop/statement/
- psn: <http://www.wikidata.org/prop/statement/value-normalized/
- psv: <http://www.wikidata.org/prop/statement/value/
- qb: <http://purl.org/linked-data/cube#
- qfn: <http://qlever.cs.uni-freiburg.de/function#
- ql: <http://qlever.cs.uni-freiburg.de/builtin-functions/
- qlss: <https://qlever.cs.uni-freiburg.de/spatialSearch/
- rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#
- rdfs: <http://www.w3.org/2000/01/rdf-schema#
- ref: <http://www.wikidata.org/reference/
- s: <http://www.wikidata.org/entity/statement/
- schema: <http://schema.org/
- skos: <http://www.w3.org/2004/02/skos/core#
- v: <http://www.wikidata.org/value/
- void: <http://rdfs.org/ns/void#
- wd: <http://www.wikidata.org/entity/
- wdno: <http://www.wikidata.org/prop/novalue/
- wdt: <http://www.wikidata.org/prop/direct/
- wdtn: <http://www.wikidata.org/prop/direct-normalized/
- wikibase: <http://wikiba.se/ontology#
- xsd: <http://www.w3.org/2001/XMLSchema#

Additional rules to follow:
- Explain your thought process before and after each step and function call.
- Do not just use or make up entity or property identifiers without verifying their existence in the knowledge graphs first.
- Do not ask the user for clarifications without first attempting to complete the task. If the task input is incomplete or ambiguous, try to make reasonable assumptions and document them.
- Do not use "SERVICE wikibase:label { bd:serviceParam wikibase:language ..." in SPARQL queries. It is not SPARQL standard and unsupported by the used QLever SPARQL endpoints. Use rdfs:label or similar properties to get labels instead.
- Always execute your final SPARQL query before giving an answer to make sure it returns the expected results.
- The SPARQL query should always return the actual identifiers / IRIs of the items in its result. It additionally may return labels or other human-readable information, but they are optional and should be put within optional clauses unless explicitly requested by the user.
- Do not stop early if there are still obvious improvements to be made to the SPARQL query. For example, keep refining your SPARQL query if its result contains irrelevant items or is missing items you expected.
- Do not perform additional computation (e.g. filtering, sorting, calculations) on the result of the SPARQL query to determine the answer. All computation should be done solely within SPARQL.
- For questions with a "True" or "False" answer the SPARQL query should be an ASK query.

[User] who does mila kunis play on family guy?

[Assistant]
To determine who Mila Kunis plays on Family Guy, I need to find the character she portrayed in the TV show Family Guy. This requires identifying Mila Kunis as a person and then finding her role (character) in the show Family Guy.

### Step 1: Search for Mila Kunis in Wikidata
I will first search for Mila Kunis to get her Wikidata entity identifier.

Question: mila kunis

Top 10 entity alternatives:
1. Mila Kunis (wd:Q37628), also known as Milena Markivna Kunis, Milena Markovna: has occupation television producer / has occupation television actor / has occupation child actor / has occupation voice actor / Ukrainian-American actress / has occupation film actor / has occupation Model / has occupation model / has occupation actor / is instance of human / American actress / American actress
2. Mila Rodino (wd:Q182115), also known as Dear Motherland: is instance of national anthem / national anthem of Bulgaria
3. Mila Province (wd:Q235723), also known as Province of Mila: is instance of province of Algeria / province of Algeria
4. La Pedrera (wd:Q207870, matched via Casa Milà), also known as Casa Milà: apartment building in Barcelona, designed by Antoni Gaudí / is instance of multifamily residential
5. Mila (wd:Q335676): is instance of commune of Algeria / commune and town in Algeria / is instance of town
6. El Milà (wd:Q541131), also known as El Mila: is instance of municipality of Catalonia / municipality of Spain
7. Sebastian Mila (wd:Q449496): has occupation association football player / has occupation soccer player / is instance of human / Polish footballer / Polish footballer / Polish footballer
8. Mila Doce (wd:Q976870), also known as Mila Doce, TX: census designated place in Hidalgo County, Texas, United States / is instance of census-designated place in the United States / is instance of census-designated place
9. Mila caespitosa (wd:Q136936), also known as Cactus: is instance of taxon / species of plant
10. Mila Sivatskaya (wd:Q16594250), also known as Mila Alekseevna Sivatskaya: has occupation actor / is instance of human / Ukrainian actress / Ukrainian actress / Ukrainian actor

[Assistant]
The top result is Mila Kunis (wd:Q37628), a human and actress, which matches our target. I will now investigate her roles, particularly in Family Guy, by exploring her properties.

### Step 2: Explore properties of Mila Kunis to find her roles
I will list the triples for Mila Kunis (wd:Q37628) to see if there is a property indicating her roles in TV shows, especially Family Guy.

list

wd:Q37628

Got 1,097 rows and 3 columns, showing the first 10 rows below:
| subject                | property                         | object                                                                                |
| ---------------------- | -------------------------------- | --------------------------------------------------------------------------------------------------- |
| Mila Kunis (wd:Q37628) | instance of (wdt:P31)            | human (wd:Q5)                                                                                |
| Mila Kunis (wd:Q37628) | occupation (wdt:P106)            | actor (wd:Q33999)                                                                                |
| Mila Kunis (wd:Q37628) | sex or gender (wdt:P21)          | female (wd:Q6581072)                                                                                |
| Mila Kunis (wd:Q37628) | given name (wdt:P735)            | Milena (wd:Q1759001)                                                                                |
| Mila Kunis (wd:Q37628) | date of birth (wdt:P569)         | 1983-08-14T00:00:00Z (xsd:dateTime)                                                                 |
| Mila Kunis (wd:Q37628) | Commons category (wdt:P373)      | Mila Kunis                                                                                |
| Mila Kunis (wd:Q37628) | image (wdt:P18)                  | <http://commons.wikimedia.org/wiki/Special:FilePath/Mila%20Kunis%20Bad%20Moms%202%20%282018%29.jpg> |
| Mila Kunis (wd:Q37628) | family name (wdt:P734)           | Kunis (wd:Q36991596)                                                                                |
| Mila Kunis (wd:Q37628) | country of citizenship (wdt:P27) | United States (wd:Q30)                                                                              |
| Mila Kunis (wd:Q37628) | Freebase ID (wdt:P646)           | /m/023v4_                                                                                |
| ...                    | ...                              | ...                                                                                |

[Assistant]
I see that Mila Kunis is an actor (wd:Q33999), but I don't see any direct property indicating her roles in TV shows. I need to find the property that links actors to the characters they portray.

### Step 3: Search for properties related to "role" or "character" for Mila Kunis
I will use `search_property_of_entity` to find properties related to roles or characters for Mila Kunis.

Question: role

Top 10 property alternatives:
1. member of political party (wd:P102 as p/wdt, matched via party), also known as member of, member of party, party, party membership, political party, etc.: the political party of which a person is or has been a member or otherwise affiliated / the political party of which this politician is or has been a member / the political party of which this politician is or has been a member / is subproperty of member of
2. occupation (wd:P106 as p/wdt), also known as avocation, career, craft, employ, employment, etc.: occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39) / occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39) / occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39)
3. unmarried partner (wd:P451 as p/wdt, matched via partner), also known as boyfriend, cohabitant, domestic partner, enbyfriend, girlfriend, etc.: someone with whom the person is in a relationship without being married. Use "spouse" (P26) for married couples / someone with whom the person is in a relationship without being married. Use "spouse" (P26) for married couples / is subproperty of significant person
4. spouse (wd:P26 as p/wdt, matched via partner), also known as common-law husband, common-law spouse, common-law wife, husband, husbands, etc.: the subject has the object as their spouse (husband, wife, ... Use "unmarried partner" (P451) for non-married companions / the subject has the object as their spouse (husband, wife, ... Use "unmarried partner" (P451) for non-married companions / the subject has the object as their spouse (husband, wife, ... Use "unmarried partner" (P451) for non-married companions / is subproperty of significant person / is subproperty of relative
5. given name (wd:P735 as p/wdt, matched via name), also known as Christian name, first name, forename, middle name, name, etc.: first name or another given name of this person; values used with the property should not link disambiguations nor family names / first name or another given name of this person; values used with the property shouldn't link disambiguations nor family names / first name or another given name of this person; values used with the property shouldn't link disambiguations nor family names / is subproperty of name
6. birth name (wd:P1477 as p/wdt, matched via né), also known as birthname, bn, bname, born as, full birth name, etc.: full name of a person at birth, if different from their ... John Peter Doe for Joe Doe, Ann Smith for Ann Miller) / full name of a person at birth, if different from their current, generally used name / full name of a person at birth, if different from their current name / is subproperty of name
7. number of children (wd:P1971 as p/wdt, matched via issue), also known as children, children (number), how many children, issue, kids, etc.: number of children of the person. Mainly in cases where the full list isn't or shouldn't be added in "child" (P40). / number of children of the person, animal, or character
8. child (wd:P40 as p/wdt, matched via issue), also known as children, daughter, daughters, descendants, father of, etc.: subject has object as child. Do not use for stepchildren—use "relative" (P1038), qualified with "type of kinship" (P1039) / subject has the object in their family as their offspring son or daughter (independently of their age) / subject has object as biological, foster, and/or adoptive child / is subproperty of significant person / is subproperty of relative
9. employer (wd:P108 as p/wdt, matched via organization), also known as employed by, of employer, organisation, organization, worked at, etc.: person or organization for which the subject works or worked / organisation for which the subject works or worked / organization for which the subject works or worked / is subproperty of affiliation
10. ethnic group (wd:P172 as p/wdt, matched via race), also known as (cultural) nationality, culture, ethnicity, ethnic or cultural origin, people, etc.: subject's ethnicity (consensus is that a VERY high standard ... on by scholars, or 3) is fictional and portrayed as such) / subject's ethnicity (consensus is that a VERY high standard ... on by scholars, or 3) is fictional and portrayed as such)

No other items found

[Assistant]
I don't see a direct property for "role" or "character" in the results. This suggests that roles in TV shows might be stored as statements with qualifiers rather than direct properties. I will now search for properties related to "character" or "portrayed" to find the correct property.

### Step 4: Search for properties related to "character" or "portrayed"
I will search for properties that might link an actor to a character they portray.

Question: portrayed character

Top 10 property alternatives:
1. present in work (wd:P1441 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via character in), also known as appeared in, appears in, appears in work, character in, featured in work, etc.: this (fictional or fictionalized) entity, place, or person ... P1343 for entities described in non-fictional accounts) / work in which this fictional entity (Q14897293) or historical ... P1343 for entities described in non-fictional accounts)
2. character role (wd:P453 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as acting role, as, performer of, plays, role, etc.: specific role played or filled by subject -- use only as qualifier of "cast member" (P161), "voice actor" (P725) / specific role played or filled by subject (use only as qualifier of P161 or P725)
3. depicted by (wd:P1299 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via portrayed by), also known as acted by, appears in, depicted in, found in, played by, etc.: object depicting this subject (object being creative works such as books, films, paintings)
4. performer (wd:P175 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via portrayed by), also known as actor, actress, artist, dancer, musical artist, etc.: actor, musician, band or other performer associated with this role or musical work / actor, musician, music group or other performer associated with this work / is subproperty of contributor to the creative work or subject
5. character type (wd:P9071 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via stock character), also known as archetype, character archetype, character stereotype, -dere, dere, etc.: generic character type that this fictional character represents / is subproperty of manifestation of
6. personality trait of fictional character (wd:P9652 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via trait of fictitious character), also known as character trait of fictional character, character trait of fictitious character, fictional character personality trait, fictional character personal quality, fictional character trait, etc.: particular personality trait which applies to this fictional character
7. name of the character role (wd:P4633 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via character role named as), also known as character name, character named as, character role named as, name of character role, name of role, etc.: name by which a character role is recorded in a database or ... a specific performance of a theatrical production of a play / name by which a character role is recorded in a database or ... a specific performance of a theatrical production of a play / is subproperty of name
8. depicts (wd:P180 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via portrays), also known as conveys, depicting, depiction of, displays, features, etc.: entity visually depicted in an image, literarily described in ... audiovisual or other medium; see also P921,  'main subject' / depicted entity (see also P921: main subject) / depicted entity (see also P921: main subject) / is subproperty of has part(s) / is subproperty of has part / place
9. notable role (wd:P10606 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via notable character role), also known as notable character role, notable for character role, notable for role, P10606: role in a theatrical, motion picture, television, or other work that a performer is particularly known for / is subproperty of notable works / is subproperty of notable work
10. depicted part (wd:P5961 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via part depicted), also known as part depicted, part shown, shown part, P5961: use as qualifier for "depicts" (P180)

[Assistant]
I see that **P453 (character role)** is a qualifier for roles played by actors, and **P161 (cast member)** is the main property that links an actor to a work (e.g., a TV show). Additionally, **P4633 (name of the character role)** gives the name of the character.

So, to find the character Mila Kunis played in *Family Guy*, I need to:
1. Find the *Family Guy* TV show entity.
2. Find Mila Kunis's cast member statements (P161) for *Family Guy*.
3. Use the qualifier P453 (character role) to find the character she portrayed.
4. Use P4633 (name of the character role) to get the character's name.

### Step 5: Search for the *Family Guy* TV show entity
I will search for "Family Guy" to get its Wikidata ID.

Question: family guy

Top 10 entity alternatives:
1. Family Guy (wd:Q5930): is instance of animated television series / American adult animated sitcom / American adult animated sitcom
2. Family Guy (wd:Q5433143): is instance of pinball machine game / pinball table
3. Family Guy (wd:Q55012102), also known as Family Guy franchise: is instance of media franchise / American media franchise
4. Family Guy (wd:Q108370888): is instance of video game series / video game series / video game series / video game series
5. Inside Family Guy (wd:Q27877310): is instance of television series episode / episode of Family Guy (S15 E4)
6. Family Guy: Uncensored (wd:Q18928703), also known as Uncensored: is instance of video game / iOS game
7. Family Guy Online (wd:Q5433145): is instance of video game / 2012 video game / 2012 video game / 2012 video game
8. Disney's The Reboot (wd:Q103888161, matched via Family Guy Again), also known as Family Guy Again, Lois, The Q: is instance of television series episode / episode of Family Guy (S18 E4)
9. Family Guy Lite (wd:Q102842382): is instance of television series episode / episode of Family Guy (S17 E14)
10. Family Guy controversies (wd:Q5186798), also known as Criticism of Family Guy: is instance of TV show controversy / Wikimedia list article

[Assistant]
The top result is *Family Guy* (wd:Q5930), an animated television series. This is the correct entity.

### Step 6: Construct a SPARQL query to find Mila Kunis's character in Family Guy
Now I will construct a SPARQL query to:
- Find Mila Kunis (wd:Q37628) as a cast member (P161) of *Family Guy* (wd:Q5930).
- Use the qualifier P453 (character role) to get the character she portrayed.
- Use P4633 (name of the character role) to get the character's name.
- Fetch the English label of the character.

I will execute this query.

execute

SELECT ?character ?characterLabel WHERE { wd:Q37628 wdt:P161 wd:Q5930 . ?stmt ps:P161 wd:Q5930 ; pq:P453 ?character . ?character wdt:P4633 ?characterName . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } }

[Assistant]
The query returned no results, which suggests that the structure might be different. Let me reconsider the data model.

In Wikidata, the **P161 (cast member)** property links an actor to a work (e.g., Family Guy), and the **P453 (character role)** is a qualifier on the statement. However, the character itself is often represented as an entity (e.g., Meg Griffin), and its name is stored via **P4633 (name of the character role)**.

But in many cases, the character entity might not have a P4633 statement directly. Instead, the character's name might be stored as its label.

Let me revise the query to:
- Find Mila Kunis as a cast member of Family Guy.
- Get the character entity via the qualifier P453.
- Get the label of the character in English.

I will try this corrected query:

SELECT ?character ?characterLabel WHERE { wd:Q37628 p:P161 ?stmt . ?stmt ps:P161 wd:Q5930 . ?stmt pq:P453 ?character . ?character rdfs:label ?characterLabel . FILTER(LANG(?characterLabel) = "en") }

[Assistant]
Still no results. This suggests that either:
1. Mila Kunis's role in *Family Guy* is not explicitly linked with P453 in Wikidata, or
2. The character she plays is not modeled as a separate entity with a qualifier.

Let me check if Mila Kunis is listed as a cast member of *Family Guy* at all, without qualifiers.

SELECT ?work WHERE { wd:Q37628 wdt:P161 ?work . ?work rdfs:label ?workLabel . FILTER(LANG(?workLabel) = "en") }

[Assistant]
No results again — this is surprising. Mila Kunis is a well-known voice actor on *Family Guy*, so her role should be documented. Let me check if *Family Guy* has any cast members listed at all.

### Step 7: Check if Family Guy has any cast members
I will check if *Family Guy* (wd:Q5930) has any cast members (P161) to verify the property is used.

SELECT ?actor ?actorLabel WHERE { wd:Q5930 wdt:P161 ?actor . ?actor rdfs:label ?actorLabel . FILTER(LANG(?actorLabel) = "en") } LIMIT 5

[Assistant]
This is unexpected. *Family Guy* should have cast members listed. Let me check if the property P161 is even used for this show by listing some triples related to cast members.

### Step 8: List triples for Family Guy to see how cast members are stored
I will list some triples for *Family Guy* to see if cast members are stored differently.

list

wd:Q5930

[Assistant]
No results — this suggests that **P161 (cast member)** is not directly used on the *Family Guy* item. Instead, it might be used on the **episode level** or through a different property.

Let me check if *Family Guy* has any statements using **P1441 (present in work)**, which can link characters to works.

### Step 9: Search for P1441 (present in work) on Family Guy
I will check if characters are linked to *Family Guy* via P1441.

wd:Q5930

[Assistant]
Still no results. This is puzzling. Let me try a different approach: search for Mila Kunis's roles directly, and see if any of them are linked to *Family Guy*.

### Step 10: Search for Mila Kunis's roles (P1441 or P161) without filtering by show
I will check what works Mila Kunis is associated with via P161 or P1441.

execute

SELECT ?work ?workLabel WHERE { wd:Q37628 wdt:P161 ?work . ?work rdfs:label ?workLabel . FILTER(LANG(?workLabel) = "en") } LIMIT 10

[Assistant]
Still no results. This suggests that **Mila Kunis's roles are not directly linked via P161** in Wikidata — which is unusual for a well-known actor.

Let me check if she is listed as a **voice actor** (P725) instead, since *Family Guy* is an animated series and voice acting is key.

### Step 11: Search for voice actor property (P725) for Mila Kunis
I will check if Mila Kunis has any voice acting roles linked via P725.

SELECT ?work ?workLabel WHERE { wd:Q37628 wdt:P725 ?work . ?work rdfs:label ?workLabel . FILTER(LANG(?workLabel) = "en") } LIMIT 10

[Assistant]
Still no results. This is concerning. Let me check if Mila Kunis has any statements at all related to *Family Guy* by searching for any mention of "Family Guy" in her triples.

### Step 12: Search for any mention of "Family Guy" in Mila Kunis's triples
I will search for any triple where the object contains "Family Guy" in its label.

SELECT ?property ?object ?objectLabel WHERE { wd:Q37628 ?property ?object . ?object rdfs:label ?objectLabel . FILTER(CONTAINS(LCASE(?objectLabel), "family guy")) . FILTER(LANG(?objectLabel) = "en") } LIMIT 10

[Assistant]
Ah! Here we go. Mila Kunis is linked to *Family Guy* via **P800 (notable work)**, not P161 or P725. This is a key insight.

Now, I need to find the **character** she portrayed in *Family Guy*. Since P800 links her to the show, I need to find if there's a way to link her to the specific character.

Let me check if there are any statements on Mila Kunis that link to *Family Guy* with qualifiers — perhaps using P453 (character role) on a statement where the object is *Family Guy*.

But P800 is a direct property, not a statement with qualifiers. So I need to find if the character is linked via another path.

Let me check what characters are associated with *Family Guy* via P1441 (present in work), and then see if Mila Kunis is linked to any of those characters via P453 or P1299.

### Step 13: Find characters in Family Guy (via P1441)
I will find entities that are characters in *Family Guy*.

SELECT ?character ?characterLabel WHERE { wd:Q5930 wdt:P1441 ?character . ?character rdfs:label ?characterLabel . FILTER(LANG(?characterLabel) = "en") } LIMIT 10

[Assistant]
Still no results. This is very unusual. Let me check if *Family Guy* has any characters listed at all in Wikidata.

### Step 14: Search for characters in Family Guy using search_entity
I will search for "Meg Griffin" — the character Mila Kunis voices — to see if it exists in Wikidata.

Question: meg griffin

Top 10 entity alternatives:
1. Meg Griffin (wd:Q908772), also known as Megan Griffin, Megan "Meg" Griffin, Megatron Harvey Oswald Griffin, Megatron "Meg" Harvey Oswald Griffin: fictional character from the Family Guy franchise / is instance of animated television character / has occupation high school student / is instance of fictional human
2. Meg Griffin (wd:Q6807983): has occupation radio personality / has occupation disc jockey / American radio disc jockey / is instance of human / has occupation DJ
3. Megan Kate Griffin-Pickering (wd:Q103292935): Ph.D. University of Cambridge 2019 / is instance of human
4. John Griffin, 4th Baron Howard de Walden (wd:Q4470201, matched via John Griffin Griffin), also known as John Griffin Griffin, John Whitwell: British nobleman and soldier (1719-1797) / has occupation military personnel / has occupation Military personnel / has occupation politician / is instance of human
5. Griffin, George Griffin (wd:Q111285115): entry in Alumni Oxonienses: the Members of the University of Oxford, 1715-1886 / is instance of biographical article
6. Griffin v. Griffin (wd:Q19111077): is instance of United States Supreme Court decision / United States Supreme Court case / is instance of legal case
7. griffin (wd:Q130223), also known as griffon, gryphon: is subclass of mythical hybrid / is subclass of chimaera / legendary animal
8. Meg Ryan (wd:Q167498): has occupation television actor / has occupation Character actor / has occupation character actor / has occupation voice actor / has occupation film actor / has occupation actor / is instance of human / American actress
9. Meg Whitman (wd:Q55174), also known as Margaret Cushing "Meg" Whitman, Margaret Cushing Whitman, Margaret Whitman, Meg Cushing Whitman: has occupation business executive / has occupation entrepreneur / has occupation Entrepreneur / American business executive / has occupation politician / is instance of human
10. Griffin (wd:Q1012372), also known as Griffin, GA, Griffin, Georgia: county seat of Spalding County, Georgia, United States / is instance of city of the United States / is instance of city in the United States / is instance of municipality of Georgia

[Assistant]
Perfect! **Meg Griffin (wd:Q908772)** is a fictional character from *Family Guy*, and Mila Kunis voices her.

Now I need to confirm that Mila Kunis is linked to Meg Griffin as the voice actor.

### Step 15: Check if Mila Kunis is linked to Meg Griffin via P1299 (depicted by) or P725 (voice actor)
I will check if Mila Kunis (wd:Q37628) is linked to Meg Griffin (wd:Q908772) via **P725 (voice actor)** or **P1299 (depicted by)**.

Let me try P725 first (since it's voice acting):

SELECT ?character ?characterLabel WHERE { wd:Q37628 wdt:P725 wd:Q908772 . ?character rdfs:label ?characterLabel . FILTER(LANG(?characterLabel) = "en") }

[Assistant]
No result. Let me try P1299 (depicted by) — this is usually used for portrayals in media, but might be used here.

SELECT ?character ?characterLabel WHERE { wd:Q908772 wdt:P1299 wd:Q37628 . ?character rdfs:label ?characterLabel . FILTER(LANG(?characterLabel) = "en") }

[Assistant]
Still no result. This is strange — Mila Kunis is famously the voice of Meg Griffin, so this link should exist.

Let me check if Meg Griffin has any statements about her voice actor.

list

wd:Q908772

[Assistant]
Yes! Here it is. **Meg Griffin (wd:Q908772)** has **P725 (voice actor)** pointing to **Mila Kunis (wd:Q37628)**.

This means the relationship is stored as:
**Meg Griffin → voice actor → Mila Kunis**

So, to answer the question:
> Who does Mila Kunis play on Family Guy?

The answer is **Meg Griffin**, and we have confirmed that Mila Kunis is the voice actor for Meg Griffin via P725.

### Final SPARQL Query
I will now write a clean SPARQL query to return the character Mila Kunis plays on Family Guy, using the confirmed relationship.

The query will:
- Start from Mila Kunis (wd:Q37628)
- Find the character she voices via the inverse of P725 (i.e., find entities where P725 = Mila Kunis)
- Get the label of that character in English

But since P725 is on the character, not on Mila Kunis, I need to reverse the direction.

Here’s the correct query:

execute

SELECT ?character ?characterLabel WHERE { ?character wdt:P725 wd:Q37628 . ?character rdfs:label ?characterLabel . FILTER(LANG(?characterLabel) = "en") }

Got 377 rows and 2 columns, showing the first 5 and last 5 rows below:
| character                                         | characterLabel                              |
| ------------------------------------------------- | ------------------------------------------- |
| Switch the Flip (wd:Q102820459)                   | Switch the Flip (lang:en)                   |
| HTTPete (wd:Q102820874)                           | HTTPete (lang:en)                           |
| The Unkindest Cut (wd:Q102821213)                 | The Unkindest Cut (lang:en)                 |
| Are You There God? It's Me, Peter (wd:Q102821612) | Are You There God? It's Me, Peter (lang:en) |
| Dead Dog Walking (wd:Q102822143)                  | Dead Dog Walking (lang:en)                  |
| ...                                               | ...                                         |
| Robot Chicken (wd:Q8822)                          | Robot Chicken (lang:en)                     |
| Meg Griffin (wd:Q908772)                          | Meg Griffin (lang:en)                       |
| Trading Places (wd:Q952095)                       | Trading Places (lang:en)                    |
| The Story on Page One (wd:Q958539)                | The Story on Page One (lang:en)             |
| The Courtship of Stewie's Father (wd:Q980824)     | The Courtship of Stewie's Father (lang:en)  |

[Assistant]
I see that the query returns **377 results**, including many *Family Guy* episode titles and other works. This is because **P725 (voice actor)** is being used not only for characters but also for **episodes** or **works** where Mila Kunis provided voice acting — which is incorrect usage in Wikidata.

The only correct character is **Meg Griffin (wd:Q908772)**. The other results are likely mislabeled or incorrectly linked (e.g., episodes where she voiced a character).

I need to filter for entities that are **fictional characters** (instance of Q14897293 or Q21441746).

### Step 16: Filter for fictional characters only
I will modify the query to only return entities that are instances of **fictional human** (wd:Q21441746) or **animated television character** (wd:Q14897293).

SELECT ?character ?characterLabel WHERE { ?character wdt:P725 wd:Q37628 . ?character wdt:P31 wd:Q21441746 . ?character rdfs:label ?characterLabel . FILTER(LANG(?characterLabel) = "en") }

[Assistant]
Still no results. Let me try with **wd:Q14897293** (animated television character) instead.

SELECT ?character ?characterLabel WHERE { ?character wdt:P725 wd:Q37628 . ?character wdt:P31 wd:Q14897293 . ?character rdfs:label ?characterLabel . FILTER(LANG(?characterLabel) = "en") }

[Assistant]
Still no results. This is frustrating. Let me check what **P31 (instance of)** values Meg Griffin actually has.

list

wd:Q908772

[Assistant]
Ah! Meg Griffin is an instance of:

- **animated television character** (wd:Q123126876)
- **fictional human** (wd:Q15632617)

So I need to use **wd:Q123126876** (animated television character) in my filter.

Let me update the query:

execute

SELECT ?character ?characterLabel WHERE { ?character wdt:P725 wd:Q37628 . ?character wdt:P31 wd:Q123126876 . ?character rdfs:label ?characterLabel . FILTER(LANG(?characterLabel) = "en") }

[Assistant]
Perfect! Now I have the correct result.

### ✅ Final Answer

Mila Kunis voices the character **Meg Griffin** on *Family Guy*.

The SPARQL query that confirms this is:

```sparql
SELECT ?character ?characterLabel WHERE {
  ?character wdt:P725 wd:Q37628 .
  ?character wdt:P31 wd:Q123126876 .
  ?character rdfs:label ?characterLabel .
  FILTER(LANG(?characterLabel) = "en")
}
```

This query returns **Meg Griffin** as the only animated television character voiced by Mila Kunis.

I will now provide the final answer.

answer

SELECT ?character ?characterLabel WHERE { ?character wdt:P725 wd:Q37628 . ?character wdt:P31 wd:Q123126876 . ?character rdfs:label ?characterLabel . FILTER(LANG(?characterLabel) = "en") }

Answer: Mila Kunis plays Meg Griffin on Family Guy.


PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?place WHERE {
  wd:Q1203 wdt:P20 ?place .
  ?place rdfs:label ?label .
  FILTER ( LANG( ?label ) = "en" )
}

Using entities:
- John Lennon (wd:Q1203), also known as John Ono Lennon, John Winston Ono Lennon: has occupation pianist / has occupation Film producer / has occupation actor / has occupation writer / has occupation composer / has occupation film producer / has occupation singer-songwriter / has occupation poet / has occupation recording artist / has occupation public figure / has occupation guitarist / has occupation Guitarist / has occupation peace activist / has occupation painter / has occupation film actor / has occupation political activist / has occupation prose writer / has occupation singer / has occupation record producer / has occupation film director / is instance of human / British musician (1940–1980) / English singer and songwriter, founding member of The Beatles (1940–1980)

Using properties:
- place of death (wd:P20 as wdt), also known as death location, death place, deathplace, died, died in, etc.: is subproperty of location / most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character

Answer: John Lennon died in New York City.

John Lennon died in New York City.

SPARQL query over wikidata:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?place WHERE {
  wd:Q1203 wdt:P20 ?place .
  ?place rdfs:label ?label .
  FILTER ( LANG( ?label ) = "en" )
}

Using entities:
- John Lennon (wd:Q1203), also known as John Ono Lennon, John Winston Ono Lennon: has occupation pianist / has occupation Film producer / has occupation actor / has occupation writer / has occupation composer / has occupation film producer / has occupation singer-songwriter / has occupation poet / has occupation recording artist / has occupation public figure / has occupation guitarist / has occupation Guitarist / has occupation peace activist / has occupation painter / has occupation film actor / has occupation political activist / has occupation prose writer / has occupation singer / has occupation record producer / has occupation film director / is instance of human / British musician (1940–1980) / English singer and songwriter, founding member of The Beatles (1940–1980)

Using properties:
- place of death (wd:P20 as wdt), also known as death location, death place, deathplace, died, died in, etc.: is subproperty of location / most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character

Execution result:
Got 1 row and 1 column:
| place                  |
| ---------------------- |
| New York City (wd:Q60) |

[System]
You are a question answering assistant. Your job is to generate a SPARQL query to answer a given user question.

You should follow a step-by-step approach to generate the SPARQL query:
1. Determine possible entities and properties implied by the user question.
2. Search for the entities and properties in the knowledge graphs. Where applicable, constrain the searches with already identified entities and properties.
3. Gradually build up the SPARQL query using the identified entities and properties. Start with simple queries and add more complexity as needed. Execute intermediate queries to get feedback and to verify your assumptions. You may need to refine or rethink your current plan based on the query results and go back to step 2 if needed, possibly multiple times.
4. Use the answer or cancel function to finalize your answer and stop the generation process.

Available knowledge graphs:
- wikidata at http://localhost:7001 with prefix index for entities and similarity index for properties, and notes:
  - P106 = occupation. Use wdt:P106 to get occupations and fetch English labels with rdfs:label + FILTER(LANG(?label)="en"). When returning human occupations confirm the subject is human (wdt:P31 wd:Q5) to avoid non-human items.
  - Population (P1082) and tabular (P4179): use wdt:P1082 for quick/direct values; for time-series/point-in-time use p:P1082 + ps:P1082 + pq:P585 and ORDER BY pq:P585 DESC. Inspect statement qualifiers (e.g., 'applies to part') and prov:wasDerivedFrom references (pr:P854 etc.) to detect city-proper vs metro/prefecture scopes before using values.
  - Common person properties: P31 (instance of human Q5), P106 (occupation), P569 (date of birth), P19 (place of birth), P27 (country of citizenship), P21 (sex/gender), P166 (award received). Use wdt: for direct values when possible.
  - P17 (country) can be incomplete/misleading for places (historical/overseas tags). To get modern cities in a country combine: instance-of city (P31=Q515) + wdt:P17 OR use wdt:P131* to find an admin parent whose wdt:P17 = the country. Also cross-check coordinates (P625) or admin hierarchy to spot outliers.
  - When filtering by date of birth (P569) use xsd:dateTime comparisons (e.g. >= "1900-01-01T00:00:00Z"^^xsd:dateTime). Be aware many items have year-only or imprecise dates and coverage is biased toward notable/public figures (sportspeople, politicians, artists).
  - To retrieve qualifiers (e.g., award year) use the statement/qualifier pattern: p:Pxxx / ps:Pxxx / pq:P585. Use wdt:Pxxx for normalized/direct values when you don't need qualifiers. Example: p:P166 + pq:P585 gives award year.
  - To get a person's occupations: use wdt:P106 for direct/normalized values and rdfs:label for human-readable names (FILTER(LANG(...))). Example: wd:Q... wdt:P106 ?occ . ?occ rdfs:label ?occLabel . FILTER(LANG(?occLabel)="en").
  - P166 = award received. Use wdt:P166 for normalized/direct values when you only need award items. To get award years or qualifiers use p:P166 / ps:P166 / pq:P585. Many statements lack pq:P585 — use OPTIONAL { ?stmt pq:P585 ?date } and ORDER BY DESC(?date). When listing award winners, filter ?person wdt:P31 wd:Q5 to ensure humans.
  - Population time-series pattern: wd:Q... p:P1082 ?stmt . ?stmt ps:P1082 ?pop . OPTIONAL { ?stmt pq:P585 ?date } . ORDER BY DESC(?date). pq:P585 is the point-in-time qualifier. IMPORTANT: time-series may mix scopes (city proper vs metro) — e.g., Tokyo has a 2016 entry ~38,140,000 likely metro vs smaller city figures. Inspect qualifiers/references for scope before use.
  - Use wdt:P131* to traverse the admin hierarchy and compare wdt:P17 on the place vs an admin parent to detect historical/colonial country assignments. When mismatches appear, inspect the admin parent's instance-of (P31), labels, qualifiers and references to interpret the historical scope.
  - wdt:P106 often yields multiple occupations for a person. Use GROUP_CONCAT(DISTINCT ?occLabel; separator=", ") or return multiple rows. Always fetch labels with rdfs:label + FILTER(LANG(?label)="en") to get readable occupation names.
  - When a search_entity returns multiple hits (person vs sculpture vs memorial), confirm you selected the human/statements by checking wdt:P31 (instance of) and relevant wdt: properties (e.g., wdt:P106). This avoids using a non-human QID by mistake.
  - search_autocomplete can be constrained with a SPARQL pattern containing ?search (e.g., SELECT * WHERE { ?search wdt:P31 wd:Q5 }). Use constraints to focus results (e.g., humans) and avoid ambiguous fallbacks; if it returns no results, fallback to search_entity and verify wdt:P31.
  - Use search_property_of_entity to find relevant properties for an entity (e.g., 'award' -> P166) and search_object_of_property to discover candidate objects (e.g., 'physicist' for P106). This reduces guessing P/Q ids and surfaces qualifiers.
  - Inspect statement references and qualifiers: use prov:wasDerivedFrom on p: statements to find sources, and check qualifiers (e.g., 'applies to part' or other scope qualifiers) to disambiguate city vs metro vs admin area. Reference labels can be empty; inspect reference node properties for URLs or publication dates.

Index types used for entities and properties:
- Prefix index: Retrieves items by overlap between query keywords and item words. The query keywords can match item words exactly or as prefixes.
- Similarity index: Retrieves items by cosine similarity between their embeddings and the query embedding.

General notes across knowledge graphs:
- Use rdfs:label + FILTER(LANG(?label)="en") for labels; avoid SERVICE wikibase:label. Use wdt:Pxxx for normalized/direct values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access statement qualifiers (e.g., award year via pq:P585). When dates matter, prefer xsd:dateTime and watch for year-only precision.
- Practical query patterns: use rdfs:label + FILTER(LANG(...)) for labels. Use wdt:Pxxx for direct/normalized values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access qualifiers (dates via pq:P585). For dates use xsd:dateTime and expect year-only precision. For places: combine P17 with P131 or coordinate (P625) filters to avoid historical/overseas mismatches.
- Use OPTIONAL for pq: qualifiers (e.g., pq:P585), sort by qualifier (ORDER BY pq:P585 DESC) to prefer recent values. Use GROUP_CONCAT to combine multiple labels/values in one row. Watch for typed literals (xsd:dateTime, xsd:decimal) when filtering or sorting.
- Before querying, use search_entity to resolve human-friendly names to wd:Q identifiers and verify instance-of (e.g., check wdt:P31 = wd:Q5 for humans) to avoid ambiguous matches. Prefer the top match but programmatically confirm P31 before using its data.
- Use search_property to confirm property identifiers (e.g., "country" -> P17) before embedding them in queries. This prevents mistakes from assuming an ID and helps pick the best property if multiple choices exist.
- search_autocomplete can fall back to an unconstrained search or error when there are too many candidates. If this happens (e.g., "more than the maximum supported number of subject candidates"), retry with narrower constraints such as instance-of (wdt:P31), additional type filters, or short prefixes to reduce the candidate set; otherwise fallback to search_entity and verify wdt:P31.
- Use list(...) to inspect all triples on an entity for exploration, but expect large results for notable items. Prefer wdt: properties or targeted p:/ps:/pq: patterns in SPARQL when you need normalized values or qualifiers, respectively.
- Before embedding property or item IDs in SPARQL, use search_property, search_property_of_entity, and search_object_of_property to discover the appropriate P/PID or object QIDs. This reduces errors from guessing IDs and surfaces better property alternatives and qualifiers.
- search_constrained and search_autocomplete can return no results for constrained queries or when the index is large. If they fail, fallback to search_entity + verify P31 (or use search_property_of_entity). Constrain with instance-of (wdt:P31) or other properties in the SPARQL to improve matches.
- When selecting awards by year, prefer xsd:dateTime range filters (e.g., >= "2001-01-01T00:00:00Z"^^xsd:dateTime && < "2002-01-01T00:00:00Z"^^xsd:dateTime) instead of YEAR() for portability and precision.
- When selecting award winners via wdt:P166, filter ?person wdt:P31 wd:Q5 to ensure humans — fictional characters or non-humans may have award claims. If you need award years use p:P166 / ps:P166 / pq:P585 and OPTIONAL { ?stmt pq:P585 ?year } to retrieve qualifier years.
- Use wdt:P625 (coordinates) together with wdt:P131* and wdt:P17 checks to validate a place's modern country or to filter by geography. When country labels mismatch historically, inspect admin parents and coordinates to resolve whether the item refers to historical/colonial scope or current boundaries.
- Prefer wdt:Pxxx for normalized/direct values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access qualifiers (e.g., pq:P585 for award year). Always fetch labels with rdfs:label + FILTER(LANG(?label) = "en").
- If search_autocomplete returns too many candidates or errors, retry with constraints (e.g., SELECT * WHERE { ?search wdt:P31 wd:Q5 }) or narrower query text. If still failing, fallback to search_entity and verify wdt:P31 for type checks.
- For award-year queries use p:P166 / ps:P166 / pq:P585 to access award statements and year qualifiers. Filter by xsd:dateTime ranges (e.g., >= "2020-01-01T00:00:00Z"^^xsd:dateTime && < "2021-01-01T00:00:00Z"^^xsd:dateTime) instead of YEAR() for robustness.
- Use search_property_of_entity to surface relevant properties for an entity (e.g., 'birth' -> P569/P19). list(...) can inspect triples but may return large results for notable items—prefer targeted wdt: patterns (wdt:Pxxx) or p:/ps:/pq: patterns when you need qualifiers.

SPARQL prefixes for use in function calls:
- bd: <http://www.bigdata.com/rdf#
- cc: <http://creativecommons.org/ns#
- data: <https://www.wikidata.org/wiki/Special:EntityData/
- dc: <http://purl.org/dc/elements/1.1/
- dct: <http://purl.org/dc/terms/
- foaf: <http://xmlns.com/foaf/0.1/
- geo: <http://www.opengis.net/ont/geosparql#
- geof: <http://www.opengis.net/def/function/geosparql/
- gn: <http://www.geonames.org/ontology#
- hint: <http://www.bigdata.com/queryHints#
- imdb: <https://www.imdb.com/
- math: <http://www.w3.org/2005/xpath-functions/math#
- ontolex: <http://www.w3.org/ns/lemon/ontolex#
- owl: <http://www.w3.org/2002/07/owl#
- p: <http://www.wikidata.org/prop/
- pq: <http://www.wikidata.org/prop/qualifier/
- pqn: <http://www.wikidata.org/prop/qualifier/value-normalized/
- pqv: <http://www.wikidata.org/prop/qualifier/value/
- pr: <http://www.wikidata.org/prop/reference/
- prn: <http://www.wikidata.org/prop/reference/value-normalized/
- prov: <http://www.w3.org/ns/prov#
- prv: <http://www.wikidata.org/prop/reference/value/
- ps: <http://www.wikidata.org/prop/statement/
- psn: <http://www.wikidata.org/prop/statement/value-normalized/
- psv: <http://www.wikidata.org/prop/statement/value/
- qb: <http://purl.org/linked-data/cube#
- qfn: <http://qlever.cs.uni-freiburg.de/function#
- ql: <http://qlever.cs.uni-freiburg.de/builtin-functions/
- qlss: <https://qlever.cs.uni-freiburg.de/spatialSearch/
- rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#
- rdfs: <http://www.w3.org/2000/01/rdf-schema#
- ref: <http://www.wikidata.org/reference/
- s: <http://www.wikidata.org/entity/statement/
- schema: <http://schema.org/
- skos: <http://www.w3.org/2004/02/skos/core#
- v: <http://www.wikidata.org/value/
- void: <http://rdfs.org/ns/void#
- wd: <http://www.wikidata.org/entity/
- wdno: <http://www.wikidata.org/prop/novalue/
- wdt: <http://www.wikidata.org/prop/direct/
- wdtn: <http://www.wikidata.org/prop/direct-normalized/
- wikibase: <http://wikiba.se/ontology#
- xsd: <http://www.w3.org/2001/XMLSchema#

Additional rules to follow:
- Explain your thought process before and after each step and function call.
- Do not just use or make up entity or property identifiers without verifying their existence in the knowledge graphs first.
- Do not ask the user for clarifications without first attempting to complete the task. If the task input is incomplete or ambiguous, try to make reasonable assumptions and document them.
- Do not use "SERVICE wikibase:label { bd:serviceParam wikibase:language ..." in SPARQL queries. It is not SPARQL standard and unsupported by the used QLever SPARQL endpoints. Use rdfs:label or similar properties to get labels instead.
- Always execute your final SPARQL query before giving an answer to make sure it returns the expected results.
- The SPARQL query should always return the actual identifiers / IRIs of the items in its result. It additionally may return labels or other human-readable information, but they are optional and should be put within optional clauses unless explicitly requested by the user.
- Do not stop early if there are still obvious improvements to be made to the SPARQL query. For example, keep refining your SPARQL query if its result contains irrelevant items or is missing items you expected.
- Do not perform additional computation (e.g. filtering, sorting, calculations) on the result of the SPARQL query to determine the answer. All computation should be done solely within SPARQL.
- For questions with a "True" or "False" answer the SPARQL query should be an ASK query.

[User] where do john lennon die?

[Assistant]
To determine where John Lennon died, I need to find the location of his death. This information is typically stored in Wikidata using the property "place of death" (P20).

### Step 1: Search for John Lennon in Wikidata
I will first search for the entity corresponding to John Lennon.

Question: john lennon

Top 10 entity alternatives:
1. John Lennon (wd:Q1203), also known as John Ono Lennon, John Winston Ono Lennon: English singer and songwriter, founding member of The Beatles (1940–1980) / has occupation political activist / has occupation singer-songwriter / has occupation recording artist / has occupation record producer / has occupation peace activist / has occupation film producer / has occupation Film producer / has occupation public figure / has occupation film director / British musician (1940–1980) / has occupation prose writer / has occupation film actor / has occupation guitarist / has occupation Guitarist / has occupation composer / has occupation pianist / has occupation painter / has occupation writer / has occupation singer / has occupation actor / is instance of human / has occupation poet
2. Liverpool John Lennon Airport (wd:Q8727, matched via John Lennon), also known as John Lennon, John Lennon airport, Liverpool Airport, Liverpool (John Lennon), LPL: is instance of commercial traffic aerodrome / is instance of international airport / airport in Liverpool, England / is instance of airport
3. John Lennon Silva Santos (wd:Q6244563, matched via John Lennon), also known as John Lennon: has occupation association football player / has occupation soccer player / is instance of human / Brazilian footballer / Brazilian footballer / Brazilian footballer
4. John Brown Lennon (wd:Q6223555, matched via John Lennon), also known as John B. Lennon, John Lennon: American labor leader (1850–1923) / has occupation trade unionist / is instance of human
5. John Lennon (wd:Q11979004), also known as J. John Lennon, Justin John Lennon: has occupation university teacher / has occupation tourism scholar / Scottish tourism researcher / is instance of human
6. John Lennon (wd:Q12871620): is instance of human / 1855 - 3 Aug 1921
7. John Lennon (wd:Q65548791): Irish hurler born 1996 / is instance of human
8. John Lennon (wd:Q6244553): has occupation Military personnel / has occupation military personnel / British naval captain / is instance of human
9. John Lennon (wd:Q124098904): is instance of musical work/composition / song
10. John Lennon (wd:Q131601487): journal article from 'Radical History Review' published in 1980 / is instance of scholarly article / is instance of academic article

[Assistant]
The top result is John Lennon (wd:Q1203), the English singer and songwriter, founding member of The Beatles. This is the correct entity we are looking for. Now, I will check the properties of this entity to find the "place of death" (P20).

### Step 2: List the properties of John Lennon (wd:Q1203) to find the place of death
I will use the `list` function to inspect the triples associated with John Lennon, focusing on properties related to death.

list

wd:Q1203

[Assistant]
The property `wdt:P20` (place of death) for John Lennon (wd:Q1203) is linked to New York City (wd:Q60).

### Step 3: Confirm the label of the place of death (New York City)
To ensure clarity, I will retrieve the English label for New York City (wd:Q60) to confirm it is correctly identified.

wd:Q60

Got 298 rows and 3 columns, showing the first 10 rows below:
| subject                | property   | object                           |
| ---------------------- | ---------- | -------------------------------- |
| New York City (wd:Q60) | rdfs:label | Āltepētl Yancuīc York (lang:nah) |
| New York City (wd:Q60) | rdfs:label | Bandar Raya New York (lang:ms)   |
| New York City (wd:Q60) | rdfs:label | Belt ta' New York (lang:mt)      |
| New York City (wd:Q60) | rdfs:label | Caayr York Noa (lang:gv)         |
| New York City (wd:Q60) | rdfs:label | Çĕнĕ Йорк (lang:cv)              |
| New York City (wd:Q60) | rdfs:label | Dakbayan sa New York (lang:ceb)  |
| New York City (wd:Q60) | rdfs:label | Dinas Efrog Newydd (lang:cy)     |
| New York City (wd:Q60) | rdfs:label | Eabhraig Nuadh (lang:gd)         |
| New York City (wd:Q60) | rdfs:label | Evrek Nowydh (lang:kw)           |
| New York City (wd:Q60) | rdfs:label | Kin Yótʼááh Deezʼá (lang:nv)     |
| ...                    | ...        | ...                              |

[Assistant]
I can see that there are many language labels for New York City (wd:Q60), but I need to specifically retrieve the English label to confirm it.

### Step 4: Query for the English label of New York City (wd:Q60)
I will execute a SPARQL query to get the English label for New York City.

execute

SELECT ?label WHERE { wd:Q60 rdfs:label ?label . FILTER(LANG(?label) = "en") }

Got 1 row and 1 column:
| label                   |
| ----------------------- |
| New York City (lang:en) |

[Assistant]
The English label for New York City (wd:Q60) is "New York City", which confirms the place of death.

### Final Answer:
John Lennon died in New York City.

I will now provide the final SPARQL query that retrieves this information.

answer

SELECT ?place WHERE { wd:Q1203 wdt:P20 ?place . ?place rdfs:label ?label . FILTER(LANG(?label) = "en") }

Answer: John Lennon died in New York City.


PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?team ?teamLabel WHERE {
  wd:Q221048 wdt:P54 ?team .
  ?team rdfs:label ?teamLabel .
  FILTER ( LANG( ?teamLabel ) = "en" )
}

Using entities:
- Jackie Robinson (wd:Q221048), also known as Jack Roosevelt "Jackie" Robinson: has occupation baseball player / has occupation athletics competitor / has occupation military officer / has occupation officer / has occupation vice president / has occupation basketball coach / is instance of human / American baseball player

Using properties:
- member of sports team (wd:P54 as wdt), also known as club played for, member of team, of team, part of team, played for, etc.: is subproperty of member of / sports teams or clubs that the subject currently represents or formerly represented / sports teams or clubs that the subject currently represents or formerly represented / sports teams or clubs that the subject represents or represented

Answer: Jackie Robinson played for the Los Angeles Dodgers.

Jackie Robinson played for the Los Angeles Dodgers.

SPARQL query over wikidata:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?team ?teamLabel WHERE {
  wd:Q221048 wdt:P54 ?team .
  ?team rdfs:label ?teamLabel .
  FILTER ( LANG( ?teamLabel ) = "en" )
}

Using entities:
- Jackie Robinson (wd:Q221048), also known as Jack Roosevelt "Jackie" Robinson: has occupation baseball player / has occupation athletics competitor / has occupation military officer / has occupation officer / has occupation vice president / has occupation basketball coach / is instance of human / American baseball player

Using properties:
- member of sports team (wd:P54 as wdt), also known as club played for, member of team, of team, part of team, played for, etc.: is subproperty of member of / sports teams or clubs that the subject currently represents or formerly represented / sports teams or clubs that the subject currently represents or formerly represented / sports teams or clubs that the subject represents or represented

Execution result:
Got 1 row and 2 columns:
| team                             | teamLabel                     |
| -------------------------------- | ----------------------------- |
| Los Angeles Dodgers (wd:Q334634) | Los Angeles Dodgers (lang:en) |

[System]
You are a question answering assistant. Your job is to generate a SPARQL query to answer a given user question.

You should follow a step-by-step approach to generate the SPARQL query:
1. Determine possible entities and properties implied by the user question.
2. Search for the entities and properties in the knowledge graphs. Where applicable, constrain the searches with already identified entities and properties.
3. Gradually build up the SPARQL query using the identified entities and properties. Start with simple queries and add more complexity as needed. Execute intermediate queries to get feedback and to verify your assumptions. You may need to refine or rethink your current plan based on the query results and go back to step 2 if needed, possibly multiple times.
4. Use the answer or cancel function to finalize your answer and stop the generation process.

Available knowledge graphs:
- wikidata at http://localhost:7001 with prefix index for entities and similarity index for properties, and notes:
  - P106 = occupation. Use wdt:P106 to get occupations and fetch English labels with rdfs:label + FILTER(LANG(?label)="en"). When returning human occupations confirm the subject is human (wdt:P31 wd:Q5) to avoid non-human items.
  - Population (P1082) and tabular (P4179): use wdt:P1082 for quick/direct values; for time-series/point-in-time use p:P1082 + ps:P1082 + pq:P585 and ORDER BY pq:P585 DESC. Inspect statement qualifiers (e.g., 'applies to part') and prov:wasDerivedFrom references (pr:P854 etc.) to detect city-proper vs metro/prefecture scopes before using values.
  - Common person properties: P31 (instance of human Q5), P106 (occupation), P569 (date of birth), P19 (place of birth), P27 (country of citizenship), P21 (sex/gender), P166 (award received). Use wdt: for direct values when possible.
  - P17 (country) can be incomplete/misleading for places (historical/overseas tags). To get modern cities in a country combine: instance-of city (P31=Q515) + wdt:P17 OR use wdt:P131* to find an admin parent whose wdt:P17 = the country. Also cross-check coordinates (P625) or admin hierarchy to spot outliers.
  - When filtering by date of birth (P569) use xsd:dateTime comparisons (e.g. >= "1900-01-01T00:00:00Z"^^xsd:dateTime). Be aware many items have year-only or imprecise dates and coverage is biased toward notable/public figures (sportspeople, politicians, artists).
  - To retrieve qualifiers (e.g., award year) use the statement/qualifier pattern: p:Pxxx / ps:Pxxx / pq:P585. Use wdt:Pxxx for normalized/direct values when you don't need qualifiers. Example: p:P166 + pq:P585 gives award year.
  - To get a person's occupations: use wdt:P106 for direct/normalized values and rdfs:label for human-readable names (FILTER(LANG(...))). Example: wd:Q... wdt:P106 ?occ . ?occ rdfs:label ?occLabel . FILTER(LANG(?occLabel)="en").
  - P166 = award received. Use wdt:P166 for normalized/direct values when you only need award items. To get award years or qualifiers use p:P166 / ps:P166 / pq:P585. Many statements lack pq:P585 — use OPTIONAL { ?stmt pq:P585 ?date } and ORDER BY DESC(?date). When listing award winners, filter ?person wdt:P31 wd:Q5 to ensure humans.
  - Population time-series pattern: wd:Q... p:P1082 ?stmt . ?stmt ps:P1082 ?pop . OPTIONAL { ?stmt pq:P585 ?date } . ORDER BY DESC(?date). pq:P585 is the point-in-time qualifier. IMPORTANT: time-series may mix scopes (city proper vs metro) — e.g., Tokyo has a 2016 entry ~38,140,000 likely metro vs smaller city figures. Inspect qualifiers/references for scope before use.
  - Use wdt:P131* to traverse the admin hierarchy and compare wdt:P17 on the place vs an admin parent to detect historical/colonial country assignments. When mismatches appear, inspect the admin parent's instance-of (P31), labels, qualifiers and references to interpret the historical scope.
  - wdt:P106 often yields multiple occupations for a person. Use GROUP_CONCAT(DISTINCT ?occLabel; separator=", ") or return multiple rows. Always fetch labels with rdfs:label + FILTER(LANG(?label)="en") to get readable occupation names.
  - When a search_entity returns multiple hits (person vs sculpture vs memorial), confirm you selected the human/statements by checking wdt:P31 (instance of) and relevant wdt: properties (e.g., wdt:P106). This avoids using a non-human QID by mistake.
  - search_autocomplete can be constrained with a SPARQL pattern containing ?search (e.g., SELECT * WHERE { ?search wdt:P31 wd:Q5 }). Use constraints to focus results (e.g., humans) and avoid ambiguous fallbacks; if it returns no results, fallback to search_entity and verify wdt:P31.
  - Use search_property_of_entity to find relevant properties for an entity (e.g., 'award' -> P166) and search_object_of_property to discover candidate objects (e.g., 'physicist' for P106). This reduces guessing P/Q ids and surfaces qualifiers.
  - Inspect statement references and qualifiers: use prov:wasDerivedFrom on p: statements to find sources, and check qualifiers (e.g., 'applies to part' or other scope qualifiers) to disambiguate city vs metro vs admin area. Reference labels can be empty; inspect reference node properties for URLs or publication dates.

Index types used for entities and properties:
- Prefix index: Retrieves items by overlap between query keywords and item words. The query keywords can match item words exactly or as prefixes.
- Similarity index: Retrieves items by cosine similarity between their embeddings and the query embedding.

General notes across knowledge graphs:
- Use rdfs:label + FILTER(LANG(?label)="en") for labels; avoid SERVICE wikibase:label. Use wdt:Pxxx for normalized/direct values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access statement qualifiers (e.g., award year via pq:P585). When dates matter, prefer xsd:dateTime and watch for year-only precision.
- Practical query patterns: use rdfs:label + FILTER(LANG(...)) for labels. Use wdt:Pxxx for direct/normalized values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access qualifiers (dates via pq:P585). For dates use xsd:dateTime and expect year-only precision. For places: combine P17 with P131 or coordinate (P625) filters to avoid historical/overseas mismatches.
- Use OPTIONAL for pq: qualifiers (e.g., pq:P585), sort by qualifier (ORDER BY pq:P585 DESC) to prefer recent values. Use GROUP_CONCAT to combine multiple labels/values in one row. Watch for typed literals (xsd:dateTime, xsd:decimal) when filtering or sorting.
- Before querying, use search_entity to resolve human-friendly names to wd:Q identifiers and verify instance-of (e.g., check wdt:P31 = wd:Q5 for humans) to avoid ambiguous matches. Prefer the top match but programmatically confirm P31 before using its data.
- Use search_property to confirm property identifiers (e.g., "country" -> P17) before embedding them in queries. This prevents mistakes from assuming an ID and helps pick the best property if multiple choices exist.
- search_autocomplete can fall back to an unconstrained search or error when there are too many candidates. If this happens (e.g., "more than the maximum supported number of subject candidates"), retry with narrower constraints such as instance-of (wdt:P31), additional type filters, or short prefixes to reduce the candidate set; otherwise fallback to search_entity and verify wdt:P31.
- Use list(...) to inspect all triples on an entity for exploration, but expect large results for notable items. Prefer wdt: properties or targeted p:/ps:/pq: patterns in SPARQL when you need normalized values or qualifiers, respectively.
- Before embedding property or item IDs in SPARQL, use search_property, search_property_of_entity, and search_object_of_property to discover the appropriate P/PID or object QIDs. This reduces errors from guessing IDs and surfaces better property alternatives and qualifiers.
- search_constrained and search_autocomplete can return no results for constrained queries or when the index is large. If they fail, fallback to search_entity + verify P31 (or use search_property_of_entity). Constrain with instance-of (wdt:P31) or other properties in the SPARQL to improve matches.
- When selecting awards by year, prefer xsd:dateTime range filters (e.g., >= "2001-01-01T00:00:00Z"^^xsd:dateTime && < "2002-01-01T00:00:00Z"^^xsd:dateTime) instead of YEAR() for portability and precision.
- When selecting award winners via wdt:P166, filter ?person wdt:P31 wd:Q5 to ensure humans — fictional characters or non-humans may have award claims. If you need award years use p:P166 / ps:P166 / pq:P585 and OPTIONAL { ?stmt pq:P585 ?year } to retrieve qualifier years.
- Use wdt:P625 (coordinates) together with wdt:P131* and wdt:P17 checks to validate a place's modern country or to filter by geography. When country labels mismatch historically, inspect admin parents and coordinates to resolve whether the item refers to historical/colonial scope or current boundaries.
- Prefer wdt:Pxxx for normalized/direct values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access qualifiers (e.g., pq:P585 for award year). Always fetch labels with rdfs:label + FILTER(LANG(?label) = "en").
- If search_autocomplete returns too many candidates or errors, retry with constraints (e.g., SELECT * WHERE { ?search wdt:P31 wd:Q5 }) or narrower query text. If still failing, fallback to search_entity and verify wdt:P31 for type checks.
- For award-year queries use p:P166 / ps:P166 / pq:P585 to access award statements and year qualifiers. Filter by xsd:dateTime ranges (e.g., >= "2020-01-01T00:00:00Z"^^xsd:dateTime && < "2021-01-01T00:00:00Z"^^xsd:dateTime) instead of YEAR() for robustness.
- Use search_property_of_entity to surface relevant properties for an entity (e.g., 'birth' -> P569/P19). list(...) can inspect triples but may return large results for notable items—prefer targeted wdt: patterns (wdt:Pxxx) or p:/ps:/pq: patterns when you need qualifiers.

SPARQL prefixes for use in function calls:
- bd: <http://www.bigdata.com/rdf#
- cc: <http://creativecommons.org/ns#
- data: <https://www.wikidata.org/wiki/Special:EntityData/
- dc: <http://purl.org/dc/elements/1.1/
- dct: <http://purl.org/dc/terms/
- foaf: <http://xmlns.com/foaf/0.1/
- geo: <http://www.opengis.net/ont/geosparql#
- geof: <http://www.opengis.net/def/function/geosparql/
- gn: <http://www.geonames.org/ontology#
- hint: <http://www.bigdata.com/queryHints#
- imdb: <https://www.imdb.com/
- math: <http://www.w3.org/2005/xpath-functions/math#
- ontolex: <http://www.w3.org/ns/lemon/ontolex#
- owl: <http://www.w3.org/2002/07/owl#
- p: <http://www.wikidata.org/prop/
- pq: <http://www.wikidata.org/prop/qualifier/
- pqn: <http://www.wikidata.org/prop/qualifier/value-normalized/
- pqv: <http://www.wikidata.org/prop/qualifier/value/
- pr: <http://www.wikidata.org/prop/reference/
- prn: <http://www.wikidata.org/prop/reference/value-normalized/
- prov: <http://www.w3.org/ns/prov#
- prv: <http://www.wikidata.org/prop/reference/value/
- ps: <http://www.wikidata.org/prop/statement/
- psn: <http://www.wikidata.org/prop/statement/value-normalized/
- psv: <http://www.wikidata.org/prop/statement/value/
- qb: <http://purl.org/linked-data/cube#
- qfn: <http://qlever.cs.uni-freiburg.de/function#
- ql: <http://qlever.cs.uni-freiburg.de/builtin-functions/
- qlss: <https://qlever.cs.uni-freiburg.de/spatialSearch/
- rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#
- rdfs: <http://www.w3.org/2000/01/rdf-schema#
- ref: <http://www.wikidata.org/reference/
- s: <http://www.wikidata.org/entity/statement/
- schema: <http://schema.org/
- skos: <http://www.w3.org/2004/02/skos/core#
- v: <http://www.wikidata.org/value/
- void: <http://rdfs.org/ns/void#
- wd: <http://www.wikidata.org/entity/
- wdno: <http://www.wikidata.org/prop/novalue/
- wdt: <http://www.wikidata.org/prop/direct/
- wdtn: <http://www.wikidata.org/prop/direct-normalized/
- wikibase: <http://wikiba.se/ontology#
- xsd: <http://www.w3.org/2001/XMLSchema#

Additional rules to follow:
- Explain your thought process before and after each step and function call.
- Do not just use or make up entity or property identifiers without verifying their existence in the knowledge graphs first.
- Do not ask the user for clarifications without first attempting to complete the task. If the task input is incomplete or ambiguous, try to make reasonable assumptions and document them.
- Do not use "SERVICE wikibase:label { bd:serviceParam wikibase:language ..." in SPARQL queries. It is not SPARQL standard and unsupported by the used QLever SPARQL endpoints. Use rdfs:label or similar properties to get labels instead.
- Always execute your final SPARQL query before giving an answer to make sure it returns the expected results.
- The SPARQL query should always return the actual identifiers / IRIs of the items in its result. It additionally may return labels or other human-readable information, but they are optional and should be put within optional clauses unless explicitly requested by the user.
- Do not stop early if there are still obvious improvements to be made to the SPARQL query. For example, keep refining your SPARQL query if its result contains irrelevant items or is missing items you expected.
- Do not perform additional computation (e.g. filtering, sorting, calculations) on the result of the SPARQL query to determine the answer. All computation should be done solely within SPARQL.
- For questions with a "True" or "False" answer the SPARQL query should be an ASK query.

[User] what baseball team was jackie robinson on?

[Assistant]
To determine which baseball team Jackie Robinson played for, I will follow these steps:

1. **Identify Jackie Robinson as an entity**: First, I will search for Jackie Robinson in Wikidata to find his entity identifier (QID).
2. **Find his occupation**: Confirm that he is a baseball player by checking his occupation (P106).
3. **Find the team(s) he played for**: Look for properties related to his baseball team affiliation. This might involve checking for properties like "member of sports team" (P54) or similar.
4. **Construct and execute a SPARQL query**: Once I have the relevant properties and entities, I will construct a SPARQL query to retrieve the team(s) he played for.
5. **Return the answer**: Provide the final answer based on the query results.

Let me begin by searching for Jackie Robinson in Wikidata.

Question: jackie robinson

Top 10 entity alternatives:
1. Jackie Robinson (wd:Q221048), also known as Jack Roosevelt "Jackie" Robinson: has occupation athletics competitor / has occupation basketball coach / has occupation military officer / has occupation baseball player / has occupation vice president / American baseball player / has occupation officer / is instance of human
2. Jackie Robinson (wd:Q731871), also known as Jack Robinson, Robert Lloyd Jackson Robinson: American basketball player (1927–2022) / has occupation basketball player / is instance of human
3. Jackie Robinson (wd:Q1631748): has occupation basketball player / American basketball player / is instance of human
4. Jackie Robinson (wd:Q6116621): has occupation association football player / English footballer (1917–1972) / has occupation soccer player / is instance of human
5. Jackie Robinson (wd:Q3805723), also known as Harry Hippy, Loren Jackson Robinson: has occupation singer / is instance of human / Jamaican musician / Jamaican musician / Jamaican musician
6. Jackie Robinson (wd:Q25206446): 2016 film by Ken Burns / is instance of film
7. Jackie Robinson (wd:Q124413502): has occupation university teacher / lecturer of marketing, academic / has occupation researcher / has occupation academic / is instance of human
8. Jackie Robinson (wd:Q110043656): is instance of Saturday Night Live sketch / sketch from Saturday Night Live
9. Jackie Robinson (wd:Q100985462): college basketball player (1991–1993) South Carolina State / has occupation basketball player / is instance of human
10. Jackie Robinson (wd:Q112457903): is instance of human / 1944-

[Assistant]
The top result for Jackie Robinson is `wd:Q221048`, which corresponds to the famous American baseball player Jack Roosevelt "Jackie" Robinson. This is the correct entity we are looking for, as it is associated with the occupation "baseball player" and is an instance of a human.

Now, I will check the properties of this entity to identify the baseball team(s) he played for. Specifically, I will look for properties like "member of sports team" (P54), which is commonly used to indicate team affiliations.

I will use the `list` function to inspect some of the triples associated with `wd:Q221048` to find relevant properties.

list

wd:Q221048

[Assistant]
Great! I found that Jackie Robinson (wd:Q221048) was a member of the Los Angeles Dodgers (wd:Q334634) according to the property `wdt:P54` (member of sports team).

Now, I will construct a SPARQL query to retrieve the name of the team he played for, ensuring that we fetch the English label for the team to make the result human-readable.

The query will:
1. Select the team (`?team`) that Jackie Robinson was a member of.
2. Retrieve the English label of the team using `rdfs:label` and filter for English language.
3. Ensure the result is clear and directly answers the question.

Let me execute this SPARQL query.

execute

SELECT ?team ?teamLabel WHERE { wd:Q221048 wdt:P54 ?team . ?team rdfs:label ?teamLabel . FILTER(LANG(?teamLabel) = "en") }

[Assistant]
The SPARQL query successfully returned that Jackie Robinson played for the **Los Angeles Dodgers**.

Now, I will provide the final answer with the SPARQL query used to obtain this result.

answer

SELECT ?team ?teamLabel WHERE { wd:Q221048 wdt:P54 ?team . ?team rdfs:label ?teamLabel . FILTER(LANG(?teamLabel) = "en") }

Answer: Jackie Robinson played for the Los Angeles Dodgers.